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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b)
{
    if (a < b)
    {
        a = b;
    }
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b)
{
    if (a > b)
    {
        a = b;
    }
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    ll K;
    cin >> K;

    ll mod = 0;
    ll cnt = 0;
    ll ans = 0;
    unordered_set<ll> memo;
    while (1)
    {
        ++cnt;
        mod = (mod * 10 + 7) % K;
        if (mod == 0)
        {
            ans = cnt;
            break;
        }
        else
        {
            if (memo.find(mod) != memo.end())
            {
                ans = -1;
                break;
            }
            memo.emplace(mod);
        }
    }
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
        return 0;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), m = s.nextInt();
		long x = s.nextLong();
		long[] c = new long[n];
		long[][] a = new long[n][m];
		for(int i = 0; i < n; i++) {
			c[i] = s.nextLong();
			for(int j = 0; j < m; j++) {
				a[i][j] = s.nextLong();
			}
		}
		long ans = -1;
		for(int num = 1; num < Math.pow(2, n); num++) {
			int[] arr = new int[m];
			long temp = 0;
			for(int i = 0; i < n; i++) {
				if(((num >> i) & 1) == 1) {
					for(int j = 0; j < m; j++) {
						arr[j] += a[i][j];
					}
					temp += c[i];
				}
			}
			boolean possible = true;
			for(int i = 0; i < m; i++) {
				if(arr[i] < x) {
					possible = false;
				}
			}
			if(possible) {
				if(ans == -1) {
					ans = temp;
				} else {
					ans = Math.min(ans, temp);
				}
			}
		}
		System.out.println(ans);

	}

}


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

int main(){
  int a , b ;
  cin >> a >> b ;
  
  if ( a % 2 == 1 && b % 2 == 1 ){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <functional>
using ll = long long;
const ll mod = 1000000007;

using namespace std;

typedef std::pair<std::string,double> P;

struct less {
	bool operator()(const P& x, const P& y) const {
        if(x.second==y.second){
            return x.first < y.first;
        }
		return x.second > y.second;
	}
};
int field[201][201];
long long a, b, c, d, e;
int N;
int main() {
    cin >> N;
    for(int i=0; i<N; ++i){
        string s; cin >> s;
        if(s[0]=='M') a++;
        if(s[0]=='A') b++;
        if(s[0]=='R') c++;
        if(s[0]=='C') d++;
        if(s[0]=='H') e++;
    }
    cout << a*b*c+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+b*d*e+c*d*e << endl;
	return 0;
}

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(int (i)=0; (i)<(n); (i)++)

int main(){
  int n,x,y;
  cin >> n >> x >> y;
  const int max_n = 2*1e3;

  // vector<vector<int>> dis(max_n+1, vector<int>(max_n));
  // for(int i = 0; i < n; i++){
  //   for(int j = i + 1; j < n; j++){
  //     dis[i][j] = min(j - i, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x));
  //   }
  // }
  // for(int i = 0; i < n; i++){
  //   for(int j = i + 1; j < n; j++){
  //     if(min(j - 1, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)) == i){

  //     }
  //   }
    
  // }

  vector<vector<int>> map(max_n+1);
  for(int i = 0; i < n - 1; i++){
    map[i].push_back(i+1);
    map[i+1].push_back(i);
  }
  map[x - 1].push_back(y - 1);
  map[y - 1].push_back(x - 1);

  //calculate distance to all node from node i
  vector<vector<int>> seen(max_n+1, vector<int>(max_n+1, -1));
  for(int i = 0; i < n; i++){
    queue<int> todo;
    todo.push(i);
    seen[i][i] = 0;
    int now;
    while(!todo.empty()){
      now = todo.front();
      todo.pop();

      for(auto next : map[now]){
        if(seen[i][next] == -1) {
          seen[i][next] = seen[i][now] + 1;
          todo.push(next);
        }
      }
    }
  }

  int count[max_n + 1] = {};

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      count[seen[i][j]] ++;
    }
  }
  // cout << count / 2 << endl;
  for(int k = 1; k < n; k++){
    cout << count[k] / 2 << endl;
  }
  


  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();
    
    bool is_same = true;
    for (int i = 2; i < len; i++) {
        if (s.at(i) != s.at(i - 2)) {
            is_same = false;
            break;
        }
    }
    if (is_same) {
        cout << "Second" << endl;
        return 0;
    }

    if ((s.at(0) == s.at(len - 1) && len % 2 == 0) || (s.at(0) != s.at(len - 1) && len % 2 == 1)) cout << "First" << endl;
    else cout << "Second" << endl;
}   

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

using namespace std;

int main(){
    long long N, M, V, P; cin >> N >> M >> V >> P;
    vector<long long> A(N);
    for(auto& t : A) cin >> t;
    sort(A.begin(), A.end());
    int L = -1, R = N-1;
    while(R-L > 1){
        int mid = (L+R)/2;
        long long thr = A[mid] + M;
        int gr = 0;
        long long add = M;
        for(int j=N-1;j>=0;j--){
            if(j == mid) continue;
            if(A[j] > thr){
                gr++;
                add += M;
            } else {
                if(gr+1 < P && A[j]+M > thr){
                    gr++;
                    add += M;
                } else {
                    add += min(M, thr-A[j]);
                }
            }
        }
        if(gr < P && add >= M*V) R = mid;
        else L = mid;
    }
    cout << N-R << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const double PI = 3.141592653589793238463;
const ll N=2e5+9;
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    ll ans=x/11*2;
    x%=11;
    if (x>6)
        ans+=2;
    else if (x)
        ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  std::vector<ll> ans_list;
  while(true){
    ll D,n,m;
    cin >> D;
    if(D==0) break;
    cin >> n >> m;
    ll d[n];
    d[0] = 0;
    REP(i,n-1) cin >> d[i+1];
    ll k[m];
    REP(i,m) cin >> k[i];
    sort(d,d+n);
    sort(k,k+m);
    ll ans = 0;
    REP(i,m){
      ll itr = upper_bound(d,d+n,k[i])-d;
      ll min_d = abs(d[itr]-k[i]);
      min_d = min(min_d,abs(d[itr-1]-k[i]));
      min_d = min(min_d,k[i]);
      min_d = min(min_d,D-k[i]);
      ans+= min_d;
    }
    ans_list.push_back(ans);
  }
  for(auto ans : ans_list){
    cout << ans << endl;
  }
  return 0;
}



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

namespace ARC091A {
    class Program {
        static void Main(string[] args) {
            long[] input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            long N = input[0];
            long M = input[1];
            long ans = 0;
            if (N == 1 && M == 1) {
                ans = 1;
            } else if (N == 1) {
                ans = M - 2;
            } else if (M == 1) {
                ans = N - 2;
            } else {
                ans = (N - 2) * (M - 2);
            }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  #define int long long
  int n;
  cin >> n;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }
  if (n % 2 == 1)
  {
    for(int i = n-1; i >= 0; i -= 2) cout << v[i] << " ";
    for(int i = 1; i <= n-2; i += 2) cout << v[i] << " ";
    cout << endl;
  }
  if (n % 2 == 0)
  {
    for(int i = n-1; i >= 1; i -= 2) cout << v[i] << " ";
    for(int i = 0; i <= n-2; i += 2) cout << v[i] << " ";
    cout << endl;
  }

}

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


int main(){
  int x,y;
  cin >> x >> y;
  for(int a=0;a<=x;++a){
    int b=x-a;
    if(2*a+4*b==y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return  0;
}


Measured memory_bytes: 3632
n, x = map(int,raw_input().split())
x = min(n-x,x)
ans = 0
def cal(ans,l,s):
    ans += l/s*s*3
    if l%s == 0:
        return ans
    else:
        return cal(ans,max(s,l%s),min(s,l%s))
print cal(ans,n-x,x)

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp;
#define ll long long

long long knap(vector<ll> &weight, vector<ll> &val, ll max_weight, ll n , ll index)
{
   ///sort obj in increasing orderof weight
   vector<pair<ll,ll>> obj(n);
   for(int i=0 ; i<n ; i++)
    obj[i].first = weight[i] , obj[i].second = val[i];
   sort(obj.begin() , obj.end());

    /// init DP array , DP[i][j] = max profit with weight "j" by considering all "i"th objects
    dp = vector<vector<ll>> (n+1 , vector<ll>(max_weight+1));

    for(ll i=1 ; i<=n ; i++)                    /// obj == { weight , val }
    {
        for(ll j=1 ; j<=max_weight ; j++)
        {
            if( obj[i-1].first <= j)
                dp[i][j] = max(
                           dp[i-1][j] ,                               /// object not selected
                           dp[i-1][max( 0ll , j-obj[i-1].first)] + obj[i-1].second /// obj selected
                              );
            else
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    //for(auto i:dp)    {        for(auto j:i)            cout<<j<<"\t";        cout<<endl;    }
    return dp[n][max_weight];
}
int main()
{
    ll n,  max_weight;
    cin>>n>>max_weight;
    dp = vector<vector<ll>>(n+1 , vector<ll>(max_weight+1,-1));

    vector<ll> val(n) , weight(n);
    for(ll i=0 ; i<n ; i++)
        cin>>weight[i] >> val[i];

    ll ans = knap(weight , val , max_weight , n , 0);
    cout<<endl<<ans;
}


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

// 重み付き Union Find 木
struct WeightedUnionFind {
  vector<int> parent, rank, diff_weight;

  WeightedUnionFind(int N = 1) {
    init(N);
  }

  void init(int N = 1) {
    parent.resize(N);
    rank.resize(N);
    diff_weight.resize(N);
    for (int i = 0; i < N; i++) {
      parent.at(i) = i;
      rank.at(i) = 0;
      diff_weight.at(i) = 0;
    }
  }

  int root(int x) {
    if (parent.at(x) == x) return x;
    else {
      int r = root(parent.at(x));
      diff_weight.at(x) += diff_weight.at(parent.at(x));
      parent.at(x) = r;
      return r;
    }
  }

  int weight(int x) {
    root(x);
    return diff_weight.at(x);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  // ノード y はノード x より w 重い
  bool merge(int x, int y, int w) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank.at(x) < rank.at(y)) {
      swap(x, y);
      w = -w;
    }
    if (rank.at(x) == rank.at(y)) rank.at(x)++;
    parent.at(y) = x;
    diff_weight.at(y) = w;
    return true;
  }

  int diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int main() {
  int N, M; cin >> N >> M;
  WeightedUnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int L, R, D; cin >> L >> R >> D;
    L--; R--;
    if (uf.issame(L, R)) {
      if (uf.diff(L, R) != D) { cout << "No" << endl; return 0; }
    }
    else uf.merge(L, R, D);
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e6+3;
ll ans=0;
ll jie[N],ni[N];
struct node{
	int x,y,fl;
	void init(int a,int b,int c){
		x=a,y=b,fl=c;
	}
}p[20];
int tot;
int x3,y3,x4,y4;
int xx[10],yy[10];
ll qm(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1) ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
ll C(int n,int m){
	return jie[n]*ni[m]%mod*ni[n-m]%mod;
} 
ll G(int x1,int y1,int x2,int y2){
	ll A=abs(x2-x1),B=abs(y2-y1);
	return C(A+B,B);
}
ll sol(int x1,int y1,int x2,int y2,int f1,int f2){
	///cout<<x1<<" "<<y1<<" and "<<x2<<" "<<y2<<endl;
	//cout<<x3<<" && "<<y3<<" :: "<<x4<<" && "<<y4<<endl;
	ll ret=0;
	for(ri x=x3;x<=x4;++x){
		ret=(ret+G(x1,y1,x,y4)*G(x,y4+1,x2,y2)%mod*(x+y4+1))%mod;
		//cout<<ret<<endl;
		ret=(ret-G(x1,y1,x,y3-1)*G(x,y3,x2,y2)%mod*(x+y3)%mod+mod)%mod;
		
	}
	for(ri y=y3;y<=y4;++y){
		ret=(ret+G(x1,y1,x4,y)*G(x4+1,y,x2,y2)%mod*(x4+y+1))%mod; 
		ret=(ret-G(x1,y1,x3-1,y)*G(x3,y,x2,y2)%mod*(x3+y)%mod+mod)%mod;
	} 
	//cout<<ret<<endl;
	ret=ret*(f1*f2);
	
	return ret;
}
int main(){
	int x,y;
	for(ri i=1;i<=6;++i)scanf("%d",&xx[i]);
	for(ri i=1;i<=6;++i)scanf("%d",&yy[i]);
	jie[0]=1;
	for(ri i=1;i<=N-2;++i) jie[i]=jie[i-1]*i%mod;
	//cout<<jie[N-2]<<endl;
	ni[N-2]=qm(jie[N-2],mod-2);
	//cout<<qm(jie[N-3],mod-2)<<endl;
	for(ri i=N-3;i>=0;--i) ni[i]=ni[i+1]*(i+1)%mod;
	//cout<<ni[N-3]<<endl;
	
	x3=xx[3],y3=yy[3],x4=xx[4],y4=yy[4];
	p[1].init(xx[1]-1,yy[1]-1,1);p[2].init(xx[2],yy[1]-1,-1);
	p[3].init(xx[1]-1,yy[2],-1);p[4].init(xx[2],yy[2],1);
	
	p[5].init(xx[5],yy[5],1);p[6].init(xx[6]+1,yy[5],-1);
	p[7].init(xx[5],yy[6]+1,-1);p[8].init(xx[6]+1,yy[6]+1,1);
	
	for(int i=1;i<=4;++i){
		for(int j=5;j<=8;++j){
			ans=(ans+sol(p[i].x,p[i].y,p[j].x,p[j].y,p[i].fl,p[j].fl)+mod)%mod;
		}  
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 31488
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var N = NextInt();
		var dic = new HashSet<string>();
		for (var i = 0; i < N; i++) {
			dic.Add(NextString());
		}
		WriteLine(dic.Count == 3 ? "Three" : "Four");
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  int sum = 0;
  int tmp = N;
  while(tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
  }

  OK(N % sum == 0);

  return 0;
}



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

ll factorial[1000009];
ll rfactorial[1000009];
int H,W,A,B;

ll mod_pow(ll x, ll n) {
    ll a = 1;
    while (n) {
        if (n%2) a = a*x%INF;
        x = x*x%INF;
        n/=2;
    }
    return a;
}

ll nCr(ll n, ll r) {
    ll ret = factorial[n] * rfactorial[r] % INF;
    ret *= rfactorial[n-r];
    return ret % INF;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> H >> W >> A >> B;
    factorial[0] = 1;
    rfactorial[0] = 1;
    FOR(i,1,1000001) {
        factorial[i] = factorial[i-1] * i % INF;
        rfactorial[i] = mod_pow(factorial[i], INF-2);
    }
    
    ll ans = 0;
    FOR(i,B,W) {
        ll h,w;
        h = H-A-1, w = i;
        ll tmp = nCr(h+w, h);
        h = A-1, w = W-i-1;
        tmp *= nCr(h+w, w);
        ans += tmp%INF;
    }
    
    cout << ans%INF << endl;
    
    return 0;
}

Measured memory_bytes: 16000
n = int(input())
a = [int(i) for i in input().split()]
s = sum(a) / 2
i = 0
j=0
while i < n and j < s:
    j += a[i]
    i += 1
ans1 = abs(sum(a[:i]) - sum(a[i:n]))
ans2 = abs(sum(a[:i-1]) - sum(a[i-1:n]))
print(min(ans1, ans2))


Measured memory_bytes: 89804
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
int main(){
  string s,t;
  cin >>s>>t;
  ll ss=s.size();
  ll a[26];
  for(ll i=0;i<26;i++) a[i]=-1;
  for(ll i=0;i<ss;i++){
    ll j=s[i]-'0'-49,tt=t[i]-'0'-49;
    if(a[j]==-1){//初めての出現
       for(ll k=0;k<26;k++){//同時に同じ字に変わったらだめ
         if(k==j) continue;
         if(a[k]==tt){
           cout <<"No"<<endl;
           return 0;
         }
       }
       a[j]=tt;
    }
    else{
      if(a[j]!=t[i]-'0'-49){//同じ文字が同じに変換されていない
        cout <<"No"<<endl;
        return 0;
      }
    }
  }
  cout <<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vii vector<vi>
#define pb push_back

signed main(){
  int N; cin>>N;
  string S; cin>>S;
  int ans=0;
  vi R(N+1),G(N+1),B(N+1);
  for(int i=1;i<=N;++i){
    R[N-i]=R[N-i+1];
    G[N-i]=G[N-i+1];
    B[N-i]=B[N-i+1];
    if(S[N-i]=='R') R[N-i]++;
    else if(S[N-i]=='G') G[N-i]++;
    else B[N-i]++;
  }
  for(int i=0;i<N-2;++i)
  {
    for(int j=i+1;j<N-1;++j)
    {
      set<char> s;
      s.insert('R');
      s.insert('G');
      s.insert('B');
      s.erase(S[i]);
      s.erase(S[j]);
      if(s.size()==1){
        char X=*s.begin();
        if(X=='R'){
          ans+=R[j];
        }
        else if(X=='B'){
          ans+=B[j];
        }
        else{
          ans+=G[j];
        }
        int k=j+j-i;
        if(k<N&&S[k]==X) ans--;
      }
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define N 100000
using namespace std;

int stoi(char c){
  if('A'<=c&&c<='Z')return c-'A'+10;
  if('a'<=c&&c<='z')return c-'a'+36;
  return c-'0';
}

int main(){
  int n,p,num,ans=0;
  string m;
  cin>>n;
  while(n--){
    cin>>p>>m;
    num=0;
    for(int i=0;i<m.size();i++)
      num=num*p+stoi(m[i]);
    ans^=num;
  }
  if(ans)cout<<"win"<<endl;
  else cout<<"lose"<<endl;
  return 0;
}

Measured memory_bytes: 1200
H,W = map(int,input().split())
S = [input() for i in range(H)]

from collections import deque
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
dist = [[0]*W for i in range(H)]
visited = [[0]*W for i in range(H)]
visited[0][0] = 1
q = deque([(0,0)])
while q:
    x,y = q.popleft()
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if visited[ny][nx]: continue
        if S[ny][nx] == '#': continue
        visited[ny][nx] = 1
        dist[ny][nx] = dist[y][x] + 1
        q.append((nx,ny))
w = sum(row.count('.') for row in S)
if visited[-1][-1]:
    print(w - 1 - dist[-1][-1])
else:
    print(-1)

Measured memory_bytes: 3380
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;

    if((A + B) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (A + B) / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
    int n,w;
    scanf("%d %d",&n, &w);
    int arr[n+1];
    for(int i=0; i<=n; i++)
        arr[i]=i;
    while(w--){
        char s[3];
        //scanf("%s", s);
        //int a=s[0]-'0', b=s[2]-'0';
        int a,b;
        scanf("%d,%d",&a,&b);
        //cin>>a>>,>>b;
        int memo=arr[a];
        arr[a]=arr[b];
        arr[b]=memo;
    }
    for(int i=1; i<=n; i++)
        printf("%d\n", arr[i]);
    return 0;
}


Measured memory_bytes: 2620
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

struct Edge {
public:
	int from, to;
	Edge() {}
	Edge(int _from, int _to) {
		from = _from;
		to = _to;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


vi memo;
Graph G;
int dfs(int s) {
	if (memo[s] != -1) {
		return memo[s];
	}
	if (SZ(G[s]) == 0) {
		memo[s] = 0;
		return 0;
	}
	int ret = 0;
	for (Edge e : G[s]) {
		ret = max(ret, dfs(e.to) + 1);
	}
	memo[s] = ret;
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	memo = vi(N,-1);
	G = Graph(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(Edge(a, b));
	}
	int ans = 0;
	REP(i, N) {
		ans = max(ans, dfs(i));
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;

int x3 = x2 + (y1 - y2);
int y3 = y2 + (x2 - x1);
int x4 = x3 - (x2 - x1);
int y4 = y3 - (y2 - y1);

cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const int mod = 1000000007;
int n,m;
std::vector<int> s;
std::vector<char> c;
string ans; bool can=false;
int main(){ //srand((unsigned)time(NULL));
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for (size_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (size_t i = 0; i < 1000000; i++) {
    string a = to_string(i);
    bool y = true;
    for (size_t l = 0; l < m; l++) {
      if(a[s[l]-1] != c[l])y = false;
    }
    if(a.length() == n && y){
      can = true;
      ans = a;
      break;
    }
  }
  cout << (can ? ans : "-1") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s  = sc.next();
        String[] t = {"SUN", "MON","TUE","WED","THU", "FRI","SAT"};
        for (int i = 0; i < 7 ; i++) {
            if (s.equals(t[i])) {
                System.out.println(7 - i);
            }
        }

    }

}

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

int main(){
	
	string s,t;
	int ans = 0;
	
	cin >> s;
	
	cin >> t;
	
	if (s[0] == t[0]){
		ans++;
	} 
	if (s[1] == t[1]){
		ans++;
	} 
	if (s[2] == t[2]){
		ans++;
	}
	
	cout << ans;
	
}

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

int main(){
	int n,m;
	for(int i=0; i<4; i++){
		cin>>n;
		if(n==1){
			cin>>m;
			cout<<m*6000<<endl;
		}
		else if(n==2){
			cin>>m;
			cout<<m*4000<<endl;
		}
		else if(n==3){
			cin>>m;
			cout<<m*3000<<endl;
		}
		else if(n==4){
			cin>>m;
			cout<<m*2000<<endl;
		}
	}
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,t;
	cin >> n >> t;
	vector<long long> v(t+1);
	for (int i=0; i<n; ++i){
		int w,val;
		cin >> w >> val;
		for (int k=t-w; k>=0; --k) v[k+w] = max(v[k+w],v[k]+val);
	}
	cout << *max_element(v.begin(),v.end());
	return 0;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, a: usize);
    println!("{}", a + a * a + a * a * a);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2140
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;

int main(){
    int n;
    double tmp, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> tmp;
        sum += (1/tmp);
    }

    // double hoge = (1/sum)

    cout << fixed << setprecision(8) << (1/sum) << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[]args){
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		String[] b=new String[a];
		HashMap<String,Integer> m=new HashMap<String,Integer>();
		//Arrays.sort(b);
		for(int i=0;i<a;i++){
			b[i]=s.next();
			int c=s.nextInt();
			if(!m.containsKey(b[i]))m.put(b[i],c);
			else m.put(b[i],m.get(b[i])+c);
		}
		Arrays.sort(b);
		for(int i=1;i<6;i++){
			for(int j=0;j<a;j++){
				if(j==0||!b[j].equals(b[j-1])){
					if(b[j].length()==i)System.out.println(b[j]+" "+m.get(b[j]));
				}
			}
		}
	}
}

Measured memory_bytes: 42676
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

const int N = 100000;
const ll M = ((ll)1<<40);

ll n, l;
ll num[N], m[N];

bool isBig(int current, ll t){ // current is bigger: true
  if(current == 0 || current == n - 1) return 0;
  return num[current] > t;
}

ll solve(int current, int dir){
  //cout << "current = " << current << " m = " << m[current] << endl;
  if(current < 0 || current >= n) return 0;
  if(m[current] < M) return m[current];
  //for(int i = 0; i < (int)n; i++) cout << m[i] << ' ';cout << endl;

  ll right, left;
  right = left = -1;

  if(current == 0) left = 0;
  if(current == n - 1) right = 0;
  
  if(right == -1){
    if(dir != 1 && num[current] < num[current + 1]){
      right = solve(current + 1, 2);
    }else{
      right = 0;
    }
  }

  if(left == -1){
    if(dir != 2 && num[current] < num[current - 1]){
      left = solve(current - 1, 1);
    }else{
      left = 0;
    }
  }

  //cout << "current = " << current << " right = " << right << " left = " << left <<endl;
  m[current] = max(right, left) + l - num[current];
  //cout << "m = " << m[current] << " current = " << current << endl;


  /*
  if((current == 0 || num[current] > num[current - 1]) &&
     (current == n - 1 || num[current] > num[current + 1])){
    m[current] = l - num[current];
  }else if(dir == 0){ // first

    if(isBig(current - 1, num[current]) && isBig(current + 1, num[current]))
      m[current] = max(solve(current - 1, 1), solve(current + 1, 2)) + l - num[current];
    else if(isBig(current - 1, num[current]))
      m[current] = solve(current - 1, 1) + l - num[current];
    else
      m[current] = solve(current + 1, 2) + l - num[current];

  }else if(dir == 1){ // from right
    if(isBig(current - 1, num[current]))
      m[current] = solve(current - 1, 1) + l - num[current];
    else 
      m[current] = l - num[current];
  }else{ // from left
    if(isBig(current + 1, num[current]))
      m[current] = solve(current + 1, 2) + l - num[current];
    else 
      m[current] = l - num[current];
  }
  */
  return m[current];
}

int main(){
  while(cin >> n >> l && n|l){
    for(int i = 0; i < (int)n; i++){
      cin >> num[i];
      m[i] = M;
    }

    ll ans = 0;

    for(int i = 0; i < (int)n; i++){
      if(m[i] == M) solve(i, 0);
      //for(int j = 0; j <(int)n; j++) cout << m[j] << ' ';cout << endl;
      ans = max(ans, m[i]);
    }

    //for(int i = 0; i < (int)n; i++) cout << m[i] << ' ';cout << endl;

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2388
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }
    int count = 0;
    int now = 0;

    while(now >= 0 && now != 1) {
        count++;
        int next = A[now];
        A[now] = -1;
        now = next;
    }
    if(now == -1){
        cout << -1 << endl;
    } else {
        cout << count << endl;
    }

    return 0;
}


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

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

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N, K;
    int A[210000] = {0};

    cin >> N >> K;
    rep(i,N){
        int a;
        cin >> a;
        A[a] += 1;
    }

    sort(A, A + 200000, greater<int>());

    int Ksum = 0;
    rep(i,K){
        Ksum += A[i];
    }

    if(Ksum != N){
        cout << N - Ksum << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
const int maxn = 200009;

int a[maxn],b[maxn],A[2][maxn],B[2][maxn];
int n,ans;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) b[i]=read();
	for(int i=0;i<=28;i++)
	{
		long long cnt=0;
		memset(A,0,sizeof A);
		memset(B,0,sizeof B);
		for(int j=1;j<=n;j++)
		{
			if(a[j]&(1<<i)) A[1][++A[1][0]]=a[j]%(1<<i);
			else A[0][++A[0][0]]=a[j]%(1<<i);
		}
		for(int j=1;j<=n;j++)
		{
			if(b[j]&(1<<i)) B[1][++B[1][0]]=b[j]%(1<<i);
			else B[0][++B[0][0]]=b[j]%(1<<i);
		}
		sort(A[0]+1,A[0]+1+A[0][0]);sort(A[1]+1,A[1]+1+A[1][0]);
		sort(B[0]+1,B[0]+1+B[0][0]);sort(B[1]+1,B[1]+1+B[1][0]);
//		if(i==2) debug(A[0][0]),debug(A[1][0]),debug(B[0][0]),debug(B[1][0]);
		int poi=B[0][0]+1;
		for(int j=1;j<=A[0][0];j++)
		{
//			if(i==2) debug(A[0][j]);
			while(poi>1&&B[0][poi-1]>=(1<<i)-A[0][j]) poi--;
			cnt+=B[0][0]-poi+1;
//			if(i==2) debug(B[0][0]-poi+1),debug(poi);
		}
//		if(i==2) debug(cnt);
		poi=B[1][0];
		for(int j=1;j<=A[0][0];j++)
		{
			while(poi&&B[1][poi]>=(1<<i)-A[0][j]) poi--;
			cnt+=poi;
		}
//		if(i==2) debug(cnt);
		poi=B[0][0];
		for(int j=1;j<=A[1][0];j++)
		{
			while(poi&&B[0][poi]>=(1<<i)-A[1][j]) poi--;
			cnt+=poi;
		}
//		if(i==2) debug(cnt);
		poi=B[1][0]+1;
		for(int j=1;j<=A[1][0];j++)
		{
			while(poi>1&&B[1][poi-1]>=(1<<i)-A[1][j]) poi--;
			cnt+=B[1][0]-poi+1;
		}
//		if(i==2) debug(cnt);
		if(cnt&1) ans+=(1<<i);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4992
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        int n = ni();
        int m = ni();
        long[] a = nlongs(n);
        long[] b = new long[m];
        long[] c = new long[m];
        Operation[] opes = new Operation[m];
        
        for (int i = 0; i < m; i++) {
            b[i] = ni();
            c[i] = ni();
            opes[i] = new Operation(b[i], c[i]);
        }
        Arrays.sort(opes);
        Arrays.sort(a);
        
        int idxOpe = m-1;
        for (int i = 0; i < n; i++) {
            
            long opeC = opes[idxOpe].c;
            if (a[i] >= opeC) {
                break;
            }
            a[i] = opeC;
            opes[idxOpe].b--;
            
            if (opes[idxOpe].b == 0) {
                idxOpe--;
            }
            
            if (idxOpe == -1) {
                break;
            }
        }
        
        so.println(LongStream.of(a).sum());
    }
    
    public static class Operation implements Comparable<Operation> {
        public long b;
        public long c;
        public Operation(long b, long c) {
            this.b = b;
            this.c = c;
        }
        @Override
        public int compareTo(Operation that) {
            return (int) (this.c - that.c);
        }
        @Override
        public String toString() {
            return "Ope[b: " + b + ", c: " + c + "]";
        }
    }
    
    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int padding) {
        long[] a = new long[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


Measured memory_bytes: 97456
#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;
	template<typename T>
	using vec = vector<T>;
	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 = 1e16;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	
	signed main(){
		IOS;
		string s;
		cin >> s;
		string t[16] = {
			"AKIHABARA", "AKIHABAR", "AKIHABRA","AKIHABR",
			"AKIHBARA", "AKIHBAR", "AKIHBRA", "AKIHBR",
			"KIHABARA", "KIHABAR", "KIHABRA","KIHABR",
			"KIHBARA", "KIHBAR", "KIHBRA", "KIHBR"
		};
		REP(i, 16){
			if(s == t[i]){
				dump("YES");
				return 0;
			}
		}
		dump("NO");
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,m;cin>>n>>m;
    ll mi=inf;
    ll idx=inf;
    vector<vector<ll> >g(n);
    rep(i,m){
        ll a,b;cin>>a>>b;
        a--;b--;
        g[a].pb(b);
    }
    rep(i,n){
        queue<ll>q;
        vector<ll>d(n,-1);
        q.push(i);
        d[i]=0;
        while(!q.empty()){
            ll k=q.front();
            q.pop();
            for(auto e:g[k]){
                if(e==i&&d[k]+1<mi){
                    mi=d[k]+1;
                    idx=i;
                }
                else if(d[e]>=0)continue;
                else {
                    d[e]=d[k]+1;
                    q.push(e);
                }
            }
        }
    }
    if(mi==inf)cout<<-1<<endl;
    else{
        queue<ll>q;
        vector<ll>d(n,-1);
        vector<ll>pre(n,-1);
        q.push(idx);
        d[idx]=0;
        ll s,t;
        while(!q.empty()){
            ll k=q.front();
            q.pop();
            for(auto e:g[k]){
                if(e==idx&&d[k]+1==mi){
                    t=k;
                    s=idx;
                }
                else if(d[e]>=0)continue;
                else {
                    d[e]=d[k]+1;
                    pre[e]=k;
                    q.push(e);
                }
            }
        }
        vector<ll>ans(0);
        ll now=t;
        while(now!=s){
            ans.pb(now);
            now=pre[now];
        }
        ans.pb(s);
        cout<<ans.size()<<endl;
        rep(i,ans.size()){
            cout<<ans[i]+1<<endl;
        }
    }
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
int main(){
    int n;
    int abc[3001];
    abc[0]=1;
    abc[3000]=1;
    for(int i=2;i<1502;i++){
        abc[i-1]=abc[i-2]+i;
        if(1000<i-1)
            abc[i-1]-=((i-1)-1000)*3;
        abc[3000-(i-1)]=abc[i-1];
    }
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        int is=n-1000;
        if(is<0)
            is=0;
        for(int i=is;i<n+1&&i<3001;i++){
            ans+=abc[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1196
package main

import (
	"fmt"
)

func main() {
	var n, t, a float64
	fmt.Scan(&n, &t, &a)
	hs := make([]float64, int(n))
	var tbyh float64
	gosa := 100000000.0
	r := -1
	for i := range hs {
		fmt.Scan(&hs[i])
	}
	//hi no kion motomeru
	for i := range hs {
		tbyh = t - hs[i]*0.006
		if abs(a-tbyh) <= gosa {
			gosa = abs(a - tbyh)
			r = i + 1
		}
	}
	fmt.Println(r)
}

func abs(j float64) float64 {
	if j < 0 {
		j = -j

	}
	return j
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
ll a[N];
ll b[N];
int vis[N];
void solve(){
	ll n,x,m; 
	cin>>n>>x>>m;	
	if(n<=m){
		ll ans = x;
		for(int i=2;i<=n;i++){
			x = (x*x)%m;
			ans+=x;
		}
		cout<<ans<<endl;
		return ;
	}
	a[1] = x;
	ll sum = 0;
	vis[x] = 1;
	b[1] = x;
	ll len = -1;
	ll idx = -1;
	for(int i=2;i<=m+12;i++){
		a[i] = (a[i-1]*a[i-1])%m;
		b[i]=b[i-1]+a[i];
		if(vis[a[i]]){
			sum = b[i]-b[vis[a[i]]];
			len = i-vis[a[i]];
			idx= i;
			break;
		}
		vis[a[i]] = i;
	}
	if(n<=idx){
		cout<<b[n]<<endl;
		return ;
	}
	assert(idx!=-1);
	assert(len>0);
	ll ans = b[idx-1];
	n-=idx;
	ll div = n/len;
	ans+=div*sum;
	n%=len;
	x = a[idx];
	for(int i=0;i<=n;i++){
		ans+=x;
		x = (x*x)%m;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
  ll n, sum=0;
  cin >> n;

  for(int i=1; i<=n;i++){
    if(i%3==0 && i%5==0) {
      continue;
    } else if (i%3==0){
      continue;
    } else if (i%5==0){
      continue;
    } else {
      sum+=i;
    }
  }
  cout << sum;
}

Measured memory_bytes: 3588
n,a,b = map(int, input().split())

dist = b - a
if dist % 2 == 0:
    print(dist//2)
elif a - 1 < n - b:
    print(a-1 + 1 +(b-a-1)//2)
else:
    print(n - b + 1 +(b-a-1)//2)

Measured memory_bytes: 3060
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n, m, l, i, j, k;
		long[][] a = new long[100][100], b = new long[100][100], c = new long[100][100];
		
		for(i = 0; i < 100; i++){
			for(j = 0; j < 100; j++){
				c[i][j] = 0;
			}
		}
		
		n = sc.nextInt();
		m = sc.nextInt();
		l = sc.nextInt();
		
		for(i = 0; i < n; i++){
			for(j = 0; j < m; j++){
				a[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < m; i++){
			for(j = 0; j < l; j++){
				b[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < n; i++){
			for(j = 0; j < l; j++){
				for(k = 0; k < m; k++){
					c[i][j] += a[i][k] * b[k][j];
				}
			}
		}
		
		for(i = 0; i < n; i++){
			for(j = 0; j < l; j++){
				System.out.print(c[i][j]);
				
				if(j < l-1){
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 53568
#include<bits/stdc++.h>
using namespace std;
struct edge{int to,cap,rev;};
vector<edge> v[210];
bool used[210];
void ae(int from,int to,int cap){
  v[from].push_back((edge){to,cap,v[to].size()});
  v[to].push_back((edge){from,0,v[from].size()-1});
}
int dfs(int now,int t,int f){
  if(now==t)return f;
  used[now]=true;
  for(int i=0;i<v[now].size();i++){
    edge &e=v[now][i];
    if(used[e.to]==false&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        v[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int main(){
  int n;cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  int c[n],d[n];
  for(int i=0;i<n;i++){
    cin>>c[i]>>d[i];
    for(int j=0;j<n;j++){
      if(a[j]<c[i]&&b[j]<d[i]){
        ae(j,100+i,1);
        //cout<<i<<" "<<j<<endl;
      }
    }
  }
  for(int i=0;i<n;i++){
    ae(201,i,1);
    ae(i+100,202,1);
  }
  int ans=0;
  for(;;){
    fill(used,used+210,false);
    int f=dfs(201,202,1000000000);
    if(f==0){
      cout<<ans<<endl;
      return 0;
    }
    ans+=f;
  }
}

Measured memory_bytes: 384
h,n=map(int,input().split())
l=[]
ans=0
for i in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
d=[0]*10005
for i in range(h):
    for j in l:
        a,b=j[0],j[1]
        x=d[i]+b
        y=min(10004,i+a)
        if i==0 or (d[i]!=0 and d[y]==0):
            if d[y]==0:
                d[y]=x
            else:
                d[y]=min(d[y],x)
        elif d[i]!=0 and d[y]!=0:
            d[y]=min(d[y],x)

for i in range(h,10005):
    if ans==0:
        ans=d[i]
    elif d[i]!=0:
        ans=min(ans,d[i])
print(ans)


Measured memory_bytes: 42332
//{Headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=1e5;
int N,Q,par[MAXN+1];

int root(int x){return x==par[x]?x:root(par[x]);}

void solve(){
    long long ans=0;
    char op;
    int x;
    par[1]=1;
    for(int i=2;i<=N;i++) scanf("%d",&par[i]);
    while(Q--){
        scanf(" %c %d ",&op,&x);
        if(op=='Q') ans+=root(x);
        else par[x]=x;
    }
    printf("%lld\n",ans);
}

int main(void){
//    freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&N,&Q) && N!=0)
        solve();
    return 0;
}

/*
Sample Input
6 3
1
1
2
3
3
Q 5
M 3
Q 5
0 0
Output for the Sample Input
4
*/



Measured memory_bytes: 3516
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args){
    	//final int MAX =200000;
    	   try {
     final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    	final int n = Integer.parseInt(reader.readLine());
    	//Scanner sc = new Scanner(System.in);
    	//int n = Integer.parseInt(sc.next());
    	//int n =sc.nextInt();
    	int[] R=new int[n];
    	
    	for(int i=0;i<n;i++){
    		// R[i]=Integer.parseInt(sc.next());
    		 R[i]=Integer.parseInt(reader.readLine());
    	}
    	int maxv=-2000000000;
    			 
    	int minv=R[0];
    	for(int i=1;i<n;i++){
    		maxv=Math.max(maxv,R[i]-minv);
    		minv=Math.min(minv,R[i]);
    	}
    	System.out.println(maxv);
        reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 37676
n,m = map(int,input().split())
s = list(list(map(int,input().split())) for i in range(m))
x = [-1]*n
b = True
ans = -1
for i in range(m):
    if x[s[i][0]-1] == -1 or x[s[i][0]-1] == s[i][1]:
        x[s[i][0]-1] = s[i][1]
    else:
        b = False
if len(x) != 1:
    for j in range(n):
        if x[j] == -1:
            if j == 0:
                x[j] = 1
            else:
                x[j] = 0
    if x[0] == 0:
        b = False
else:
    if x[0] == -1:
        x[0] = 0
ans = ''.join([str(c) for c in x]) if b else -1
print(ans)

Measured memory_bytes: 3064