akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){   

int a,b,c,x,y,z;   

scanf("%d%d%d",&a,&b,&c);   

if(a > b){

x = a; a = b; b = x;

}   

if(b > c){

y = b; b = c; c = y;

}   

if(a > b){

z = a; a = b; b = z;

}   

printf("%d %d %d\n",a,b,c);   

return 0;

}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String n = sc.next();

		int sum = 0;

		for (int i = 0; i < n.length(); i++) {

			int num = Integer.parseInt(n.substring(i, i + 1));

			sum = (sum + num) % 9;
		}

		if (sum % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 50480
#include<stdio.h>
int main(){
  int a,b,cal,i;

  while(scanf("%d",&a)!=EOF)
    {
      cal=0;

      for(i=0; i*a<=(600-a); i++)
	{
	  cal=cal+(i*a)*(i*a)*a;
	}

      printf("%d\n", cal);
    }

  return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    for (ll i = k+1; i <= n; i++)
    {
        ans+=(n/i)*(i-k);
        ans+=max(0LL,(n%i)-k+1);
        if(k==0) ans--;
        //cout<< i<<"\t"<<(n/i)*(i-k)<<"\t"<< (n%i)-k+1<<endl;
    }
    
    cout<<ans<<endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
    int n;cin>>n;
    V a(n);rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll ZERO = 0;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int ret = Inf;
    for(int i = 1;i <= 100;i++) {
        int cnt = 0;
        for(int j = 0;j < N;j++) {
            cnt += (vec.at(j) - i) * (vec.at(j) - i);
        }
        ret = min(ret,cnt);
    }
    cout << ret << endl;
}

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
#define MOD 1000000007

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<ll> llStack;
typedef queue<ll> llQueue;
typedef vector<ll> llVector;
typedef list<ll> llList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll N, K;
  cin >> N >> K;
  ll d, A;
  bool have[N];
  for(int i=0;i<N;i++){
    have[i] = false;
  }
  for(int i=0;i<K;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >> A;
      have[A-1] = true;
    }
  }
  
  ll ans = 0;
  for(int i=0;i<N;i++){
    if(!have[i]){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,cnt=0;
	char a[8];
	scanf("%s",a);
	for(i=0;i<4;i++)
	{
		if(a[i]==a[i+1])
		{
			cnt++;
		}
		else
		{
			cnt=0;
		}
		if(cnt==2)break;
	}
	if(cnt==2)
	{
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	
} 

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

int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    cout << n + n*n + n*n*n << endl;
    
}


Measured memory_bytes: 3632
def main():
    n = int(input())
    a = list(map(int, input().split()))
    x, y = 0, 0
    for i, z in enumerate(sorted(a)):
        if i % 2 == (n-1) % 2:
            x += z
        else:
            y += z
    print(x - y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  vector<string> s(n); rep(i,n) cin >> s[i];
  int Xa = 0, bX = 0, bXa = 0;
  int ans = 0;
  rep(i,n){
    if(s[i][0] == 'B' && s[i][(int)s[i].size()-1] == 'A') bXa++;
    else if(s[i][0] == 'B') bX++;
    else if(s[i][(int)s[i].size()-1] == 'A') Xa++;
    rep(j,(int)s[i].size()-1) if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
  }

if(bXa){
  if(Xa+bX != 0) cout << ans+bXa+min(Xa,bX);
  else cout << ans+bXa-1;
} else cout << ans+min(Xa,bX);
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';
ll i, j, le;
int main()
{
  IOS;
  int t;
  t = 1;
  while (t--)
  {ll a,b,c,d;
    cin>>a>>b>>c>>d;
cout<<max(max(b*d,a*c),max(b*c,d*a))<<endl;
  }
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#include<string.h>
#define rep(i, a, b) for(int i=(a); i<=(b); i++)


int main(){
  int N,A,B,C,D;
  cin >> N >> A >> B >>C >> D;
  string S;
  bool flag_b= false,flag_a = false, room = false;
  cin >> S;
  //B
  rep(i,B-1,D-1){
    if(S[i]=='#'&&S[i+1]=='#') flag_b = true;
  }
  rep(i,B-1,D-2){
    if(S[i]=='.' && S[i+1]=='.' && S[i+2] == '.') room = true;
  }
  if(S[B-2]=='.'&&S[B]=='.') room = true;
  if(!flag_b) S[D-1] = '#';

  
  rep(i,A-1,C-1){
    if(S[i]=='#'&&S[i+1]=='#'&&D-1<i) {
      flag_a = true;
      //cout<<S <<endl;
    }else if(S[i]=='#'&&S[i+1]=='#'&&i<D-1&&!room) {
      flag_a = true;
      //cout<<S <<endl;
    }
  }

  //cout<<flag_a << " "<<flag_b <<endl;
  if(!flag_b && !flag_a) cout<< "Yes" << endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static int max(int a, int b){return (a > b ? a : b);}
    public static int min(int a, int b){return (a < b ? a : b);}
    public static int gcd(int a, int b){return (b > 0 ? gcd(b, a % b) : a);}
    public static int lcm(int a, int b){return a / gcd(a, b) * b;}
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt(), M = sc.nextInt();
        int flg = 0;
        List<Integer>S = new ArrayList<Integer>();
        List<Integer>C = new ArrayList<Integer>();
        for(int i = 0; i < M; i++){
            int s = sc.nextInt(), c = sc.nextInt();
            S.add(s - 1);
            C.add(c);
        }
        for(int i = 0; i <= 999; i++){
            List<Integer>t = new ArrayList<Integer>();
            for(int j = i; j > 0; j /= 10)t.add(j % 10);
            if(t.size() == 0)t.add(0);
            if(N != t.size())continue;
            Collections.reverse(t);
            int f = 1;
            for(int j = 0; j < M; j++)if(t.get(S.get(j)) != C.get(j))f = 0;
            if(f == 1){
                flg = 1;
                System.out.println(i);
                break;
            }
        }
        if(flg == 0)System.out.println(-1);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
const int oo = 1e9;
using namespace std;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int n;
int a[int(1e5 + 2)];
int mf, mt;
int main(){
	fast();
	cin >> n;
	for (int i = 0; i < n; i++){
		int x; cin >> x;
		mf += !(x % 4);
		mt += !(x % 2);
	}
	mt -= mf;
	if (mf + (mt / 2) >= (n / 2)){
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";

	return 0;
}
//mosta7il_

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = 50007;
const int M = 500;
const int B = 207;

int main()
{

	ll n;cin>>n;
	ll ans = n - 1;
	for(ll i = 2;i * i <= n;i++) {
		if(n % i == 0) {
			ans = i + n / i - 2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)



int main() {
	ll X;
	cin >> X;
	if (X >= 2000) {
		cout << 1 << endl;
		return 0;
	}
	if (X % 100 <= X / 100 * 5) {
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
	// 100 -> 0~5
	// 200 -> 0~10
	// 300 -> 0~15
	// 1000 -> 0~50
	// 2000 -> 0~100
	return 0;
}

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

int main(){

  int r;
  cin >> r;
  if(r<1200){
    cout << "ABC" << endl;
  }else	if(r>=1200 && r<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }




}



Measured memory_bytes: 256
#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>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int a,b,c;
  cin >> a >> b;
  int cnt=1;
  int ans=0;
  while(cnt<b){
    cnt += (a-1);
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c=list(map(int,input().split()))
ans=0
while 1:
	if a&1 or b&1 or c&1:
		print(ans)
		break
	if a==b and b==c:
		print('-1')
		break
	ans+=1;
	d=(c+b)>>1
	e=(a+c)>>1
	f=(a+b)>>1
	a,b,c=d,e,f

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;
 
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()
 
ll k;

 
void solve(){
 cin >> k;
 
  ll res=0;
  rep(i,1,k+1){
    if(i%3==0||i%5==0) continue; 
    res+=i;
  }
  
  cout << res << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数（ll）
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

//素因数分解？
vector<pair<ll, int>>factorize(ll n){
  vector<pair<ll, int>> res;
  for(ll i = 2; i * i <= n; ++i){
    if(n % i) continue;
    res.emplace_back(i, 0);
    while(n % i == 0){
      n /= i;
      res.back().second++;
    }
  }
if(n != 1) res.emplace_back(n, 1);
return res;

}



int main() {
int N, M;
cin >> N >> M;
vector<bool> A(N, false), B(N, false);
REP(i, M){
  int a, b;
  cin >> a >> b;
  if(a == 1) A.at(b - 1) = true;
  if(b == N) B.at(a - 1) = true;
}

REP(i, N){
  if(A.at(i) == true && B.at(i) == true) {
    cout<<"POSSIBLE"<<endl;
    return 0;
  }
}

  cout<<"IMPOSSIBLE"<<endl;
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
 int h,w;

cin>>h>>w;
string s;
for(int i=1;i<=h;i++)for(int j=0;j<w;j++){
     cin>>s;
     if(s=="snuke"){
          cout<<char('A'+j)<<i<<endl;
          return 0;
     }
}





    }





      

        


Measured memory_bytes: 256
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

a,b = i2()
if a > 0:
	print("Positive")
elif a <= 0 and 0 <= b:
	print("Zero")
else:
	if (b - a)%2 == 0:
		print("Negative")
	else:
		print("Positive")

Measured memory_bytes: 9204
//http://vivi.dyndns.org/tech/cpp/list.html#insert
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
using ll = long long;

auto itr_move(auto &itr, auto b)
{
    if (b > 0)
    {
        for (ll i = 0; i < b; i++)
        {
            itr++;
        }
    }
    else //if(b<0)
    {
        b *= -1;
        for (ll i = 0; i < b; i++)
        {
            itr--;
        }
    }
    return itr;
}

int main()
{
    ll q;
    list<ll> x;
    list<ll>::iterator itr;
    itr = x.begin();
    ll a, b;
    cin >> q;

    for(ll i=0;i<q;i++)
    {
        cin >> a;
        if (a == 0)
        {
            cin >> b;
            //cout << "*itr_bf:" << *itr << endl;
            x.insert(itr, b); //itrの前に挿入する。その後itrを
            itr--;
            //cout << "*itr_af:" << *itr << endl;

            /*cout << "\n itr:" << endl;
            for (auto aitr = x.begin(); aitr != x.end(); ++aitr)
            {
                std::cout << *aitr << "\n";
            }
            cout << "\n";*/
        }
        else if (a == 1)
        {
            cin >> b;
            //cout << "move_before" << *itr << endl;
            itr_move(itr, b);
            //cout << "move" << *itr << endl;
            //itr += c; ランダムアクセス出来ないので不可
        }
        else if (a == 2)
        {
            list<ll>::iterator tmp;
            tmp = itr;
            if (itr != x.end())
                itr++;
            x.erase(tmp);
        }
    }

    for (auto i = x.begin(); i != x.end(); ++i)
    {
        std::cout << *i << "\n";
    }

    return 0;
}


Measured memory_bytes: 18620
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};
bool dp[100010];

int main () {
  string s;
  cin >> s;

  dp[0] = 1;
  rep(i,s.size()) {
    if (!dp[i]) continue;
    for (string d : divide) {
      if (s.substr(i,d.size()) == d) {
        dp[i+d.size()] = 1;
      }
    }
  }

  cout << (dp[s.size()] ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 512
def input_from_console():
    n, k = map(int, input().split())
    return n, k


def solve(n, k):
    if k == 1:
        return 0
    return n - k


def main():
    n, k = input_from_console()
    print(solve(n, k))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 18], B[1 << 18], C[1 << 18];
long long M, D[1 << 18], E[1 << 18], F[1 << 18];
vector<long long> X, Y;

bool used[8009][8009];
bool flag[8009][8009];

int main() {
	scanf("%lld%lld", &N, &M);
	for (int i = 1; i <= N; i++) scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
	for (int i = 1; i <= M; i++) scanf("%lld%lld%lld", &D[i], &E[i], &F[i]);

	// 座圧
	for (int i = 1; i <= N; i++) {
		X.push_back(A[i]);
		X.push_back(B[i]);
		Y.push_back(C[i]);
	}
	for (int i = 1; i <= M; i++) {
		X.push_back(D[i]);
		Y.push_back(E[i]);
		Y.push_back(F[i]);
	}
	X.push_back(0);
	Y.push_back(0);
	sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end());
	sort(Y.begin(), Y.end()); Y.erase(unique(Y.begin(), Y.end()), Y.end());

	for (int i = 1; i <= N; i++) {
		int pos1 = lower_bound(X.begin(), X.end(), A[i]) - X.begin();
		int pos2 = lower_bound(X.begin(), X.end(), B[i]) - X.begin();
		int pos3 = lower_bound(Y.begin(), Y.end(), C[i]) - Y.begin();
		for (int j = (pos1 + 1) * 2; j <= (pos2 + 1) * 2; j++) used[j][(pos3 + 1) * 2] = true;
	}
	for (int i = 1; i <= M; i++) {
		int pos1 = lower_bound(X.begin(), X.end(), D[i]) - X.begin();
		int pos2 = lower_bound(Y.begin(), Y.end(), E[i]) - Y.begin();
		int pos3 = lower_bound(Y.begin(), Y.end(), F[i]) - Y.begin();
		for (int j = (pos2 + 1) * 2; j <= (pos3 + 1) * 2; j++) used[(pos1 + 1) * 2][j] = true;
	}

	queue<pair<int, int>> Q;
	int pos1 = lower_bound(X.begin(), X.end(), 0) - X.begin();
	int pos2 = lower_bound(Y.begin(), Y.end(), 0) - Y.begin();
	flag[(pos1 + 1) * 2][(pos2 + 1) * 2] = true; Q.push(make_pair((pos1 + 1) * 2, (pos2 + 1) * 2));

	/*for (int i = 1; i <= 2 * X.size() + 1; i++) {
		for (int j = 1; j <= 2 * Y.size() + 1; j++) {
			if (used[i][j] == true) cout << "#";
			else if (flag[i][j] == true) cout << ".";
			else cout << " ";
		}
		cout << endl;
	}*/

	while (!Q.empty()) {
		int sx = Q.front().first, sy = Q.front().second; Q.pop();
		int dx[4] = { -1, 0, 1, 0 };
		int dy[4] = { 0, 1, 0, -1 };
		for (int i = 0; i < 4; i++) {
			int tx = sx + dx[i], ty = sy + dy[i];
			if (tx < 1 || ty < 1 || tx >= 2 * X.size() + 2 || ty >= 2 * Y.size() + 2 || flag[tx][ty] == true || used[tx][ty] == true) continue;
			flag[tx][ty] = true;
			Q.push(make_pair(tx, ty));
		}
	}

	long long sum = 0;
	for (int i = 1; i <= 2 * X.size() + 1; i += 2) {
		for (int j = 1; j <= 2 * Y.size() + 1; j += 2) {
			if (flag[i][j] == false) continue;
			if (i == 1 || j == 1 || i == 2 * X.size() + 1 || j == 2 * Y.size() + 1) {
				cout << "INF" << endl;
				return 0;
			}
			long long vx = (i - 2) / 2;
			long long vy = (j - 2) / 2;
			sum += (X[vx + 1] - X[vx]) * (Y[vy + 1] - Y[vy]);
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 95912
N,M=map(int,input().split())
a=list(map(int,input().split()))
A=[]

for i in range(N):
    cnt=0
    num=a[i]
    while num%2==0:
        cnt+=1
        num//=2
    A.append(cnt)
A.sort()
if A[0]!=A[-1]:
    print(0)
    exit()

def lcm(x,y):
    if y>x:
        x,y=y,x
    X=x
    Y=y
    while X%Y!=0:
        X,Y=Y,X%Y
    return x*y//Y
    
LCM=a[0]

for i in range(1,N):
    LCM=lcm(LCM,a[i])
    if LCM>M*2:
        print(0)
        exit()
M-=LCM//2
if M*2>=LCM:
    ans=1
print(1+M//LCM)

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    int n, m;
        cin >> n >> m;
    vector<vector<int>> v(m);
    vector<int> isOn(m);
        for(int i=0; i<m; i++){
            int k; cin >> k;
            for(int j=0; j<k; j++){
            int a;  cin >> a;
            v.at(i).push_back(a-1);
            } 
        }
        

        for(int i=0; i<m; i++) cin >> isOn.at(i);
    ll res=0;
    for(int bit=0; bit<(1<<n); bit++){
        bool flag = true;
        for(int i=0; i<m; i++){
            int cnt=0;
            for(auto c: v.at(i)){
                if(bit & (1<<c)) cnt += 1;
            }
            if(cnt%2!=isOn.at(i)) flag = false;
        }
        if(flag) res += 1;
    }
    cout << res << endl;
            
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> cum(n+1,0);
  rep(i,n) cum[i + 1] = cum[i] + a[i];

  vector<ll> b;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j <= n; j++) b.emplace_back(cum[j] - cum[i]);
  }

  ll res = 0;

  /*上の桁から決めてく*/
  for (int d = 54; d >= 0; d--) {
    int cnt = 0;
    ll now = res | (1LL << d);/*今の桁を選ぶ場合*/
    /*選択可能か*/
    for (auto e : b) cnt += ((now & e) == now);

    if (cnt >= k) swap(res, now);
  }
  
  cout << res << endl;
  return 0;
} 

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

	int N, i, count = 0, a;

	scanf("%d", &N);

	for (i = 1; i <= N; i++) {
		scanf("%d", &a);
		if (i % 2 == 1 && a % 2 == 1)
			count++;
	}

	printf("%d", count);

	return 0;
}

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++)	cin >> s.at(i);

	sort(s.begin(), s.end());

	for(int i = 0; i < n; i++) {
		cout << s.at(i);
	}

	cout << endl;

 	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc, char *argv[]){

	int n;
	int *a;
	int i;
	int min, max;

	scanf("%d", &n);
	a = (int *)malloc(sizeof(int)*n);


	scanf("%d", &a[0]);
	min = a[0];
	max = a[0];

	for(i=1;i<n;i++){
		scanf("%d", &a[i]);
		min = min < a[i] ? min : a[i];
		max = max > a[i] ? max : a[i];
	}

	printf("%d\n", max - min);

	return 0;
}


Measured memory_bytes: 128
// https://atcoder.jp/contests/abc074/tasks/arc083_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    bool ans = true;
    ll cnt = 0;
    if (v[0] != 0) {
        ans = false;
    } else {
        REP(i, n - 1) {
            if (v[i + 1] - v[i] >= 2) {
                ans = false;
                break;
            }
            if (v[i] + 1 == v[i + 1]) {
                cnt++;
            } else {
                cnt += v[i + 1];
            }
        }
    }
    if (ans) {
        cout << cnt << endl;
    } else {
        cout << "-1\n";
    }

    return 0;
}


Measured memory_bytes: 1024
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.07.07 21:38:14
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const ll M = 1000000007;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int n, k, aa, bb;
vector<int> G[100010];
int score[100010];
int dab[100010];

void dfs(int now) {
    // printf("%d\n", now);
    int mi = 0;
    rep(i, G[now].size()) {
        int to = G[now][i];
        if (score[to] == INF) {
            continue;
        }
        mi += dab[to];
    }
    rep(i, G[now].size()) {
        int to = G[now][i];
        dab[to]++;
    }
    score[now] = k - mi;

    rep(i, G[now].size()) {
        int to = G[now][i];
        if (score[to] == INF) {
            dfs(to);
        }
    }
}

int main() {
    scanf("%d%d", &n, &k);
    rep(i, n - 1) {
        scanf("%d%d", &aa, &bb);
        G[aa - 1].pb(bb - 1);
        G[bb - 1].pb(aa - 1);
    }
    rep(i, n) {
        dab[i] = 1;
        score[i] = INF;
    }

    dfs(0);
    ll ret = 1LL;
    rep(i, n) {
        if (score[i] <= 0) {
            ret = 0;
        }
        ret = (ret * (ll)score[i]) % M;
    }
    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 8832
A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = min(A) + min(B)
for i in range(M):
    x, y, c = map(int, input().split())
    x, y = x - 1, y - 1
    ans = min(ans, A[x] + B[y] - c)

print(ans)


Measured memory_bytes: 18736
n = int(input())
x = []
for i in range(n):
    a = int(input())
    tmp = [list(map(int, input().split())) for _ in range(a)]
    x.append(tmp)
    
max_ = 0
for bit in range(1 << n):
#     print(bin(bit))
    flag = 0
    cnt = 0
    for i in range(n):
        if (bit & (1<<i)):
#             print("honest",i)
            cnt += 1
            for v in x[i]:
                if bool(bit & (1<<(v[0] - 1))) != bool(v[1]):
#                     print("    ng",v[0] - 1,bit & (1<<(v[0] - 1)),v[1])
                    flag = 1
                    break
            if flag == 1:
                break
#             print("    ok",v[0] - 1,bit & (1<<(v[0] - 1)),v[1])
    if flag == 0:
        if max_ < cnt:
#             print("renew")
            max_ = cnt
print(max_)

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

int main() {
  int N;
  cin >> N;
  int64_t count=0;
  for (int i=0; i<N; i++) {
    if ((i+1)%3!=0 && (i+1)%5!=0) count+=i+1;
  }
  cout << count << endl;
}


Measured memory_bytes: 3636
import sys
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    g = [[] for i in range(n+1)]
    for i in range(n-1):
        a, b = LI()
        g[a].append(b)
        g[b].append(a)

    s = 1
    Q = deque([s])
    ans = k
    Qappend = Q.append
    searched = [0] * (n+1)
    searched[s] = 1
    while len(Q) != 0:
        temp = 1
        v = Q.popleft()
        if v == s:
            cand = k - 1
        else:
            cand = k - 2
        for i in g[v]:
            if searched[i] == 1:
                continue
            searched[i] = 1
            temp = temp * cand % MOD
            cand -= 1
            Qappend(i)
        ans = ans * temp % MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61616
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun i -> Scanf.scanf " %d" pred
let c = ref 0
let _ = Array.iteri (fun i a -> if a_s.(a) = i then incr c) a_s; Printf.printf "%d\n" @@ !c / 2

Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
//#include <iostream>
//#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> in <<<<<<<<<<<<<<<<<<<<\n")
#define deb(x) cerr << ">>>>>>>>>>>>>>>>>>>> " << #x << " = " << x << " <<<<<<<<<<<<<<<<<<<<\n"
#define debd(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %d <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debs(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %s <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define debll(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %lld <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define deblf(x) fprintf(stderr, ">>>>>>>>>>>>>>>>>>>> %s = %lf <<<<<<<<<<<<<<<<<<<<\n", #x, x)
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
//bitmask
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}

int number_of_cities, start_point;
vi cities;

int main() {
//  freopen("C:\\Users\\user\\Desktop\\cp\\input.in", "r", stdin);
  sf("%d %d", &number_of_cities, &start_point);
  cities.reserve(12345);
  cities.push_back(start_point);
  
  while(number_of_cities--) {
    int qwe;
    sf("%d", &qwe);
    cities.push_back(qwe);
  }
  
  sort(all(cities));
  vi diff;
  
  fr(i, 0, cities.size() - 1) {
    diff.push_back(cities[i+1] - cities[i]);
  }
  
  int curr_gcd = diff[0];
  
  fr(i, 1, diff.size()) {
    curr_gcd = __gcd(curr_gcd, diff[i]);
  }
  
  pf("%d\n", curr_gcd);
  
  return 0;
}


Measured memory_bytes: 1576
#include<bits/stdc++.h>
#define ll long long
#define nl "\n"
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pcase printf("Case %d:\n",ca)
#define mx 5000009
int ca=1;
using namespace std;
int main(){

    int n ;
    cin>>n;
     if(n<30){
        cout<<"No"<<nl;
     }else{
           cout<<"Yes"<<nl;
     }

}


Measured memory_bytes: 3616
#include<iostream>
long long int const mod=1e9+7;
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int first=1;
    long long int second=1;
    long long int third=1;
    for(int i=0;i<n;i++)
    {
        first*=10;
        second*=9;
        third*=8;
        first%=mod;
        second%=mod;
        third%=mod;
    }
    long long int result=(first-second+mod)%mod;
    result*=2;
    result%=mod;
    result-=((first-third+mod)%mod);
    result+=mod;
    result%=mod;
    cout<<result;

}

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

int main()
{
	int temp;
	priority_queue<int, vector<int>,greater<int> > que;
	for(int i = 0;i < 3;i++){
		cin >> temp;
		que.push(temp);
	}
	for(int i = 0;i < 2;i++){
		cout << que.top() << " ";
		que.pop();
	}
	cout << que.top() << endl;
	return 0;
}

Measured memory_bytes: 1212
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n=int(input())
    d,x=map(int,input().split())
    aa=[]
    for _ in range(n):
        aa.append(int(input()))
    print(x + sum((d-1)//a + 1 for a in aa))

main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc041_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = 0;
  ll diff = B - A;
  if (diff % 2 == 0) {
    ans = diff / 2;
  } else {
    ll l = A + (B - A - 1) / 2;
    ll r = (N - B + 1) + (B - A - 1) / 2;
    ans = min(l, r);
  }

  cout << ans << endl;
}

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

class Graph
{
	int vertex;
	vector<vector<int>> adj;

public:
	Graph(int vertex);
	void addEdge(int u, int v);
	vector<int> top_sort();
	int longest_path();
};

Graph :: Graph(int vertex)
{
	this->vertex = vertex;
	adj.resize(vertex);
}

void Graph :: addEdge(int u, int v)
{
	/* Remember to add directed edge */
	adj[u].push_back(v);
}

vector<int> Graph :: top_sort()
{
	vector<int> inDegree(vertex);
	for(int i = 0; i < vertex; i++)
		for(auto child : adj[i])
			inDegree[child]++;

	queue<int> q;

	for(int i = 0; i < vertex; i++)
		if(inDegree[i] == 0)
			q.push(i);

	vector<int> res;
	while(not q.empty())
	{
		auto source = q.front();
		q.pop();

		res.push_back(source);

		for(auto child : adj[source])
		{
			inDegree[child]--;
			if(inDegree[child] == 0)
				q.push(child);
		}
	}

	return res;
}

int Graph :: longest_path()
{
	auto top_order = top_sort();

	int n = vertex;
	vector<int> dp(n);

	/* dp[source] is the longest path starting at i */
	reverse(top_order.begin(), top_order.end());

	for(auto source : top_order)
	{
		if(adj[source].empty())
			continue;
		
		int mx = 0;
		for(auto child : adj[source])
			mx = max(mx, dp[child]);

		dp[source] = 1 + mx;
	}

	return *max_element(dp.begin(), dp.end());
}

void solve()
{
	int vertex, edges;
	cin >> vertex >> edges;

	Graph g(vertex);
	for(int i = 0; i < edges; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;

		g.addEdge(u, v);
	}

	cout << g.longest_path() << endl;
}

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


Measured memory_bytes: 9592
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = LI()
a.sort(reverse=1)
ans = a[0] - a[2]
print(ans)

Measured memory_bytes: 38476
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int mod = (int) 1e9+7;

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

    int n;
    cin >> n;
    vi a(n);
    REP(i, n) {
        cin >> a[i];
        a[i] = a[i];
    }

    ll acc = 0;
    REP(i, n) {
        acc += a[i];
        acc %= mod;
    }

    ll ans = 0;
    REP(i, n) {
        //cout << acc << endl;
        acc -= a[i];
        if (acc < 0) acc += mod;
        ans += (a[i]* acc)%mod;
        ans %= mod;
    }

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


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	ll a[n];
	rep(i,0,n) cin>>a[i];
	sort(a,a+n);
	ret(a[n/2]-a[n/2-1]);	
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int i = 1;
		while (i < 3001) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int x = Integer.parseInt(array[0]);
			int y = Integer.parseInt(array[1]);
			if (x == 0 && y == 0) {
				break;
			} else if (x >= y) {
				System.out.println(y + " " + x);

			} else if (x < y) {
				System.out.println(x + " " + y);

			}
			i++;
		}

	}

}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> B;
    rep(i, N) {
        ll a = A[i];
        ll idx = lower_bound(B.begin(), B.end(), a) - B.begin();
        if (idx == 0) {
            B.insert(B.begin(), a);
        } else {
            B[idx-1] = a;
        }
    }
    cout << B.size() << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using namespace std;
const int N = 2e5 + 3;

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
    int a, b;
    scanf("%d %d", &a, &b);
    int c = abs(a - b);
    if (c % 2){
        puts("IMPOSSIBLE");
        return 0;
    }
    printf("%d\n", max(a, b) - c / 2);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJapps
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(input[i]);
            }

            int counter = 0;
            bool flag = true;
            while (flag)
            {
                flag = false;
                for (int i = N-1; i>0; i--)
                {
                    if (A[i] < A[i - 1])
                    {
                        int m = A[i];
                        A[i] = A[i - 1];
                        A[i - 1] = m;
                        counter++;
                        flag = true;
                    }
                }
            }

            string ans = A[0].ToString();

            for (int i = 1; i < N; i++)
            {
                ans = ans + " " + A[i].ToString();
            }

            Console.WriteLine(ans);
            Console.WriteLine(counter);
        }
    }
}

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b;
    cin >> a >> b;
    pr(max(a+b,max(a-b,a*b)));
}

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

int main(void){
    string s;
    cin >> s;
    s += " ";
    int n = s.size();
    rep(i,n-2){
        if (s[i] == s[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if (s[i] == s[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


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

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

  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N-1);
  for (int n = 0; n < N; n++)
	cin >> a[n];
  for (int n = 0; n < N; n++)
	cin >> b[n];
  for (int n = 0; n <= N; n++)
	cin >> c[n];


  int last_a = a[0];
  int sat = b[a[0]-1];

  for (int i = 1; i < N; i++) {
	if (a[i] == last_a + 1)
	  sat += c[last_a-1];
	sat += b[a[i]-1];
	last_a = a[i];
  }

  cout << sat << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    int n,m;
    int[] h,w;

    void solve(){
	Scanner sc = new Scanner(System.in);
	while(true){
	    n = sc.nextInt(); m = sc.nextInt();
	    if(n==0 && m==0) break;
	    h = new int[n];
	    w = new int[m];
	    for(int i=0; i<n; i++) h[i] = sc.nextInt();
	    for(int i=0; i<m; i++) w[i] = sc.nextInt();
	    int max = 1000*1500+1;
	    int[] hlist = new int[max];
	    int[] wlist = new int[max];

	    for(int i=0; i<n; i++){
		int sum = 0;
		for(int j=i; j<n; j++){
		    sum += h[j];
		    hlist[sum]++;
		}
	    }
	    for(int i=0; i<m; i++){
		int sum = 0;
		for(int j=i; j<m; j++){
		    sum += w[j];
		    wlist[sum]++;
		}
	    }

	    int count = 0;
	    for(int i=0; i<hlist.length; i++){
		count += hlist[i]*wlist[i];
	    }
	    
	    System.out.println(count);
	}
    }

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

Measured memory_bytes: 24000