akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int a=ir.nextInt();
		int b=ir.nextInt();
		out.println(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21332
/**
*    author:  yuya1234
*    created: 24.06.2020 11:31:09
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

char itoa(int i)
{
    switch (i)
    {
    case 0:
        return '0';
    case 1:
        return '1';
    case 2:
        return '2';
    case 3:
        return '3';
    case 4:
        return '4';
    case 5:
        return '5';
    case 6:
        return '6';
    case 7:
        return '7';
    case 8:
        return '8';
    case 9:
        return '9';
    default:
        return '0';
    }
}

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

    int H, W, cnt = 0, cntB;
    string S[52];
    int Bh[2500], Bw[2500];

    cin >> H >> W;

    REP(i, H)
    {
        cin >> S[i];
    }

    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == '#')
            {
                Bh[cnt] = i;
                Bw[cnt] = j;
                cnt++;
            }
        }
    }

    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == '.')
            {
                cntB = 0;
                REP(a, cnt)
                {
                    if ((Bh[a] == i + 1 && Bw[a] == j - 1) 
                    || (Bh[a] == i + 1 && Bw[a] == j) 
                    || (Bh[a] == i + 1 && Bw[a] == j + 1) 
                    || (Bh[a] == i && Bw[a] == j - 1) 
                    || (Bh[a] == i && Bw[a] == j + 1) 
                    || (Bh[a] == i - 1 && Bw[a] == j - 1) 
                    || (Bh[a] == i - 1 && Bw[a] == j) 
                    || (Bh[a] == i - 1 && Bw[a] == j + 1))
                    {
                        cntB++;
                    }
                }
                S[i][j] = itoa(cntB);
            }
        }
    }

    REP(i, H)
    {
        cout << S[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
const int N = 1<<10;
typedef vector<int> V;
int v[10];
int C,B,A,n;
int ans=0x3f3f3f3f;
void get(int x,V a,V b,V c)
{
    if(x>n)
    {
        if(a.empty()||b.empty()||c.empty())
            return;
        int sum1=0,sum2=0,sum3=0;
        for(int i=0;i<a.size();++i)
            sum1+=a[i];
        for(int i=0;i<b.size();++i)
            sum2+=b[i];
        for(int i=0;i<c.size();++i)
            sum3+=c[i];
        int sum=abs(sum1-A)+abs(sum2-B)+abs(sum3-C);
        if(a.size())
            sum+=(a.size()-1)*10;
        if(b.size())
            sum+=(b.size()-1)*10;
        if(c.size())
            sum+=(c.size()-1)*10;
        ans=min(ans,sum);
        return ;
    }
    V t=a;
    t.push_back(v[x]);
    get(x+1,t,b,c);

    t=b;
    t.push_back(v[x]);
    get(x+1,a,t,c);

    t=c;
    t.push_back(v[x]);
    get(x+1,a,b,t);

    get(x+1,a,b,c);    
}

int main()
{
    cin>>n;
    cin>>A>>B>>C;
    for(int i=1;i<=n;++i)
        cin>>v[i];
    V a,b,c;
    get(1,a,b,c);
    cout<<ans<<endl;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
 
int32_t main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	string s;
	cin>>s;

	int q;
	cin>>q;

	vector<char>front;
	vector<char>back;

	int count=0;
	while (q--){

		int f;
		cin>>f;

		if (f==2){
			int x;
			char y;
			cin>>x>>y;

			if (count%2==0){
				if (x==1)
					front.push_back(y);
				else
					back.push_back(y);

			}
			else{
				if (x==1)
					back.push_back(y);
				else
					front.push_back(y);
			}

		}
		else{
			count++;
		}

	}

	if (count%2==0){
		for (int i=(int)front.size()-1;i>=0;i--)
				cout<<front[i];
		for (auto k : s)
				cout<<k;
		for (auto k : back)
				cout<<k;
		cout<<'\n';
	}
	else{
		for (int i=(int)back.size()-1;i>=0;i--)
				cout<<back[i];
		for (int i=(int)s.size()-1;i>=0;i--)
				cout<<s[i];
		for (auto k : front)
				cout<<k;
		cout<<'\n';
	}

}


Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;
 
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    ll n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(ll l,ll r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};
 
int main() {
  ll n;
  string s;
  cin >> n >> s;
  for(ll i=0;i<n;i++) {
    s[i]=s[i]-'a';
  }
  RollingHash<ll,mod,31> rs(s);
  ll l=0,r=n/2+1;
  ll temp=(l+r)/2;
  while(l+1<r) {
    bool flag=false;
    for(ll i=0;i<max(n-temp+1,0LL);i++) {
      for(ll j=i+temp;j<max(n-temp+1,0LL);j++) {
        if(rs.find(i,i+temp)==rs.find(j,j+temp)) {
          flag=true;
          break;
        }
      }
      if(flag) break;
    }
    if(flag) {
      l=temp;
    }
    else {
      r=temp;
    }
    temp=(l+r)/2;
  }
  cout << l << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  
  if (op == "+") {
    cout << a+b << endl;
  }
  if (op == "-") {
    cout << a-b << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
t = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  if t[i] >= b[i]:
    ans += b[i]
  else:
    ans += t[i]
    b[i] = b[i] - t[i]
    if t[i+1] >= b[i]:
      ans += b[i]
      t[i+1] = t[i+1] - b[i]
    else:
      ans += t[i+1]
      t[i+1] = 0
print(ans)


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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

/*class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y); }
		Point operator - (Point p){ return Point(x - p.x, y - p.y); }
		Point operator * (double a){ return Point(a * x, a * y); }
		Point operator / (double a){ return Point (x / a, y / a); }

		double abs(){ return sqrt(norm()); }
		double norm(){ return x * x + y * y; }

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

class Segment{
	public:
		Point p1, p2;
		Segment(Point p1 = Point(), Point p2 = Point()): 
			p1(p1), p2(p2) {}
};

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c) , r(r) {}
};

typedef Segment Line;
typedef vector<Point> Polygon;
typedef Point Vector;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}
*/

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			A[temp-1] =i+1;
		}
		for (int i=0;i<N;i++) {
			System.out.println(A[i]+" ");
		}
	}
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N;
	cin >> N;
	vector<int32> a(N), b(N);
	REP(i, N) cin >> a[i];
	REP(i, N) cin >> b[i];
	int32 res = 0;
	int32 T = 2;
	REP(i, 29){
		vector<int32> c = b;
		REP(j, c.size()){
			c[j] = b[j]%T;
		}
		sort(all(c));
		int32 cnt = 0;
		REP(j, a.size()){
			auto l = lower_bound(all(c), T/2-a[j]%T), r = lower_bound(all(c), 2*T/2-a[j]%T);
			cnt += r-l;
			l = lower_bound(all(c), 3*T/2-a[j]%T);
			cnt += c.end()-l;
		}
		res |= (cnt&1)<<i;
		T*=2;
	}
	cout << res << endl;
}

Measured memory_bytes: 4992
import java.util.*;

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

        boolean successFlag = true;
        String str = "";
        String str_tmp = "";
        String S = sc.next();
        sc.close();
        String[] divide = {"dream", "dreamer", "erase", "eraser"};
        
        // 試験対象の文字列を反転させ、前方一致判定の誤りを防ぐ
        StringBuffer sb = new StringBuffer(S);
		S = sb.reverse().toString();
		for (int i = 0; i < 4; i++) {
		    sb = new StringBuffer(divide[i]);
		    divide[i] = sb.reverse().toString();
		}
		//System.out.println(S);
        
        for (int i = 0; i < S.length();) {
            boolean loopFlag = false;

            for (int j = 0; j < 4; j++){
                
                // 一時変数に1文節代入
                str = divide[j];
                //System.out.println(str);
            
                // 分割できるか判定
                //System.out.println(i+" "+S.length());
                //System.out.println("分割前："+str);
                //System.out.println(S.substring(i, str.length()));
                //if (str.length() + i <= S.length()) {
                //    System.out.println("分割対象："+S.substring(i, str.length() + i));
                //}
                
                // 入力文字数を超えず、なおかつ分割可能な場合、分割開始位置iに文節の文字数を足す
                if (str.length() + i <= S.length()) {
                    if (S.substring(i, str.length() + i).equals(str)) {
                        //System.out.println("分割成功："+str.length());
                        loopFlag = true;
                        i += str.length();
                        break;
                    }
                }

            }
            // どの文節でも分割できない場合失敗
            if ( !loopFlag ) {
                successFlag = false;
                break;
            }
        }
        
        if (successFlag) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}



Measured memory_bytes: 28272
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
using namespace std;

typedef long long ll;

int main() {
  ll dp[60][2];
  int N; ll K; cin >> N >> K;
  vector<ll> A(N);
  for ( int i = 0; i < N; i++ ) cin >> A[i];

  memset(dp,-1,sizeof(dp));

  dp[0][0]  = 0;

  for ( int d = 0; d < 50; d++ ) {
    ll mask = 1LL<<(50-d-1);

    int num = 0;
    for ( int i = 0; i < N; i++ ) if ( A[i] & mask ) num++;

    ll cost0 = mask*num;
    ll cost1 = mask*(N-num);

    if ( dp[d][1] != -1 ) {
      dp[d+1][1] = max(dp[d+1][1],dp[d][1]+max(cost0,cost1));
    }

    if ( dp[d][0] != -1 ) {
      if ( K & mask ) dp[d+1][1] = max(dp[d+1][1],dp[d][0]+cost0);
    }

    if ( dp[d][0] != -1 ) {
      if ( K & mask ) dp[d+1][0] = max(dp[d+1][0],dp[d][0]+ cost1);
      else dp[d+1][0] =max(dp[d+1][0],dp[d][0]+ cost0);
    }
	
  }
  cout << max(dp[50][0],dp[50][1]) << endl;
  return 0;
}


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

using namespace std;
using lint = long long;

struct tri{
  string a;
  int b;
  int c;

  bool operator<(const tri &another) const
  {
    if(a != another.a)
      return a < another.a;

    if(b != another.b)
      return b < another.b;

    return c < another.c;
  };
};

int main(void)
{
    int N;
    cin >> N;
    vector<tri> S(N);

    for(int i = 0; i < N; i++){
        cin >> S[i].a >> S[i].b;
        S[i].b *= -1;
        S[i].c = i+1;
    }

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

    for(int i = 0; i < N; i++){
        cout << S[i].c << endl;
    }

    return 0;
}

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

int main() {
  char c; cin >> c;
  if (c == 'A') cout << 'T' << endl;
  else if (c == 'T') cout << 'A' << endl;
  else if (c == 'C') cout << 'G' << endl;
  else if (c == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define MAX 10000003
using namespace std;
int main()
{
    long long int n,x,y,sum=0,c=1;
    cin>>n;
    vector<pair<ll, ll>> vec;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        vec.push_back(make_pair(y,x));
    }
    sort(vec.begin(),vec.end());
    for(ll i=0;i<n;i++)
    {
        sum+=vec[i].second;
        if(sum>vec[i].first)
        {
            c=0;
            break;
        }
    }
    if(c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;

template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	while (y) {
		if (y % 2) {
			res *= x;
			res %= m;
		}
		x = x * x % mod;
		y /= 2;
	}
	return res;
}

int n,m;
string s;
vector<int>G[200005];
vector<int>same[200005];
bool used[200005],used2[200005];
void dfs(int x){
	used[x]=true;
	used2[x]=true;
	for(int i:G[x]){
		if(s[i]!=s[x])continue;
		for(int j:G[i]){
			if(s[i]==s[j])continue;
			if(used2[j]){
				cout<<"Yes"<<endl;exit(0);
			}
			if(!used[j]){
				dfs(j);
			}
		}
	}
	used2[x]=false;
}
signed main() {
	cin>>n>>m>>s;
	rep(i,m){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n){
		if(!used[i]){
			dfs(i);
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 19972
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   
    int n;
   cin >> n;
 
   int a=0,b=0,c=0,d=0;

    rep(i,n){
          string s;
        cin >> s;
        if(s[0]=='A') a++;
        else if (s[0]=='W') b++;
        else if (s[0]=='T') c++;
        else  d++;
    }

    cout<<"AC x "<<a<<endl<<"WA x "<<b<<endl<<"TLE x "<<c<<endl<<"RE x "<<d<<endl;
 return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
int N;
ll a[MAX_N];
map<ll, ll, greater<> > mp;

void solve() {
    ll big = -1;
    ll ans = 0;
    EACH(m, mp) {
        if (big == -1 && m.second >= 4) {
            ans = m.first * m.first;
            break;
        }
        if (m.second >= 2) {
            if (big == -1) big = m.first;
            else {
                ans = big * m.first;
                break;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    int temp;
    REP(i, N) {
        cin >> temp;
        mp[temp]++;
    }
    solve();
    return 0;
}

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

int main(){

int n;
cin>>n;

if(n==3)cout<<"2 5 63"<<endl;
else{

cout<<"3 9 ";
n-=2;
int cont=0;

while(n>=2 && cont+4<=30000){
cout<<cont+2<<" "<<cont+4<<" ";
cont+=6;
n-=2;
}
cont=12;
while(n>=2 && cont+9<=30000){
cout<<cont+3<<" "<<cont+9<<" ";
cont+=12;
n-=2;
}


for(int i=0;i<n;i++)cout<<(i+1)*6<<" ";

}


return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll N,K,sum=0;
    cin>>N>>K;
    vector<ll> H(0,N);
    REP(i,N){
        ll t;cin>>t;
        H.push_back(t);
        sum+=t;
    }
    sort(H.begin(),H.end(),greater<int>());
    REP(i,min(K,N)){
        sum-=H[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// 宣言
		double money = 100000;
		final double rate = 1.05;
		int amari = 0;

		// 文字列の入力
		 BufferedReader input = new BufferedReader(new
		 InputStreamReader(System.in), 1);
		 int week = Integer.parseInt(input.readLine());

		for (int i = 1; i <= week; i++) {
			// 5%の利子を加算
			money = money * rate;
			//1000円で割ってあまりがあれば千を切り上げ、余りは引いて端数を無くす
			amari = (int) money % 1000;
			if (amari != 0) {
				money = money + 1000;
				money = money - amari;
			}
		}
		System.out.println((int)money);
	}
}

Measured memory_bytes: 16848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))


int main()
{
	ios_base::sync_with_stdio(false);

	vector<ll> v;
	ll n;cin>>n;
	while(n--){ll a;cin>>a;v.pb(a);}
	sort(all(v));reverse(all(v));

	//for(ll i:v)cout<<i<<" ";cout<<endl;

	n=sz(v);n--;
	ll ans = v[0],ix=1;n--;
	while(n){
		if(n==1){ans+=v[ix];n--;}
		else {ans+=v[ix]*2;n-=2;ix++;}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll n; cin>>n; vector<ll>v(n+2);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i) v[j]++;
    }
    ll ans=0;
    for(ll i=1;i<=n;i++) ans+=(i*v[i]);
    cout<<ans;
}


Measured memory_bytes: 81404
/*input

*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb                push_back
#define pp                pop_back
#define nl                cout << "\n"
#define MIN(con)          (*min_element(ALL(con)))
#define MAX(con)          (*max_element(ALL(con)))
#define NX(cont)          next_permutation(ALL(cont))
#define PX(cont)          prev_permutation(ALL(cont))
#define prec(n)           cout << fixed << setprecision(n)
#define PI                3.14159265358979323846264338327951
#define all(c)            c.begin(),c.end()
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define sp                cout << " "
#define mod               1000000007    //9
#define ifalse            ios_base::sync_with_stdio(false),cin.tie(NULL)

using ll = long long;
using ld = long double;
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > string toString(T a)       { return to_string(a); }  // Convert int to string
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}  // Convert string to int

ll add(ll x, ll y) { x += y; if(x >= mod) x -= mod; return x; }
ll sub(ll x, ll y) { x -= y; if(x < 0) x += mod; return x; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }

ll powr(ll a, ll b) {
    ll x = 1LL;
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}

ll inv(ll a) { return powr(a, mod - 2); }
const int inv2 = (mod + 1) >> 1;
const ll INF =  1e18;
const int inf = 1e9;

bool check(ll n)
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;
    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

/*********************************************START**************************************************************/

int main()
{
    ifalse;
    int n, m, c;
    cin >> n >> m >> c;
    vector < int > v;
    rep(i, 0, m) {
        int x;
        cin >> x;
        v.pb(x);
    }
    int cnt = 0;
    rep(i, 0, n) {
        int ans = c;
        rep(j, 0, m) {
            int x;
            cin >> x;
            ans += (v[j] * x);
        }
        if(ans > 0) {
            cnt ++;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

// 4ab < (c - a - b)^2

int main(){
  ll a, b, c;
  cin >> a >> b >> c;

  ll d = c - a - b;
  ll e = 4 * a * b;
  ll f;
  if(d <= 0){
    cout << "No" << endl;
    return 0;
  }
  else{
    f = d * d;
  }

  if(e < f)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
cnt_right = 0
cnt_left = 0
for i in range(M):
    if A[i] > X:
        cnt_right += 1
for i in range(M):
    if A[i] < X:
        cnt_left += 1
print(min(cnt_right, cnt_left))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  ll i,j,cnt=0;
  ll n;
  cin>>n;
  vector<ll> p(n),q(n),a(n);
  for(i=0;i<n;i++)cin>>p[i];
  for(i=0;i<n;i++)cin>>q[i];
  for(i=0;i<n;i++)a[i]=i+1;
  while(p!=a){
      next_permutation(a.begin(),a.end());
      cnt++;
  }
  ll t=cnt;
  cnt=0;
  for(i=0;i<n;i++)a[i]=i+1;
  while(q!=a){
      next_permutation(a.begin(),a.end());
      cnt++;
  }
  ll s=cnt;
  cout<<abs1(s-t)<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>

#define int64 long long int 

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

void ink(P, int, int map[10][10]);

int main()
{
	int map[10][10] = {0};
	int x, y, s, count, max;
	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		P p(x, y);
		ink(p, s, map);
	}
	count = max = 0;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			if(!map[i][j]) count++;
			if(max < map[i][j]) max = map[i][j];
		}
	}
	cout << count << '\n' << max << '\n';
	return 0;
}

void ink(P p, int s, int map[10][10])
{
	int dx1[4] = {1, 0, -1, 0};
	int dy1[4] = {0, 1, 0, -1};
	int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1};
	int dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
	int dx3[12] = {1, 1, 0, -1, -1, -1, 0, 1, 2, 0, -2, 0};
	int dy3[12] = {0, 1, 1, 1, 0, -1, -1, -1, 0, 2, 0, -2};
	int nx, ny;

	if(s == 1){
		map[p.first][p.second]++;
		for(int i=0; i<4; i++){
			nx = p.first + dx1[i], ny = p.second + dy1[i];
			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
				map[nx][ny]++;
		}
	}
	if(s == 2){
		map[p.first][p.second]++;
		for(int i=0; i<8; i++){
			nx = p.first + dx2[i], ny = p.second + dy2[i];
			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
				map[nx][ny]++;
		}
	}
	if(s == 3){
		map[p.first][p.second]++;
		for(int i=0; i<12; i++){
			nx = p.first + dx3[i], ny = p.second + dy3[i];
			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
				map[nx][ny]++;
		}
	}
	return;
}

Measured memory_bytes: 1200
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
import sys
input=sys.stdin.readline
n,k,l = map(int, input().split())
uf_road = UnionFind(n)
uf_train = UnionFind(n)
for i in range(k):
    p,q=list(map(int, input().split()))
    uf_road.union(p-1, q-1)
for i in range(l):
    p,q=list(map(int, input().split()))
    uf_train.union(p-1, q-1)

from collections import defaultdict
d = defaultdict(int)
for i in range(n):
    d[uf_road.find(i), uf_train.find(i)] += 1
print(*(d[uf_road.find(i), uf_train.find(i)] for i in range(n)))

Measured memory_bytes: 105820
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n,z;

int main(){
	fast_io();
	int n;
	cin >> n;
	bool y = (n % 100) >= 1 && (n % 100) <= 12;
	bool m = (n / 100) >= 1 && (n / 100) <= 12;
	if(y & m)cout << "AMBIGUOUS" << '\n';
	else if(y)cout << "YYMM" << '\n';
	else if(m)cout << "MMYY" << '\n';
	else cout << "NA" << '\n';
}


Measured memory_bytes: 256
n = int(input())
csf = [list(map(int,input().split()))for i in range(n-1)]

for i in range(n):
    time = 0
    for j in range(i,n-1):
        c = csf[j][0]
        s = csf[j][1]
        f = csf[j][2]
        if time < s:time =s
        elif time%f == 0:p = 1
        else:time +=f-(time%f)
        time +=c
    print(time)
    


Measured memory_bytes: 42220
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in); 
		int N = 0;
		for (int i = 1; i <= 5; i++) {
			if (input.nextInt()==0) N = i;
		}
		System.out.println(N);
	}	
}

Measured memory_bytes: 27000
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int ans = X / (Y + Z);
    if((Y + Z) * ans + Z > X) {
        ans--;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    for (int i = min(a, b); i >= 0; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            k--;
        }
        if (!k)
        {
            cout << i << endl;
            break;
        }
    }
    return (0);
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int main() {
	IOS();
	ll m = 114514, M = 0;
	for (int i = 0; i < 5; i++) {
		ll a;
		cin >> a;
		m = min(a, m);
		M = max(a, M);
	}
	ll k;
	cin >> k;
	dump(M - m > k ? ":(" : "Yay!");
	return 0;
}

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

bool isPrime( long long x )
{
	if( x < 2 ) return false;
	if( x == 2 ) return true;
	if( x % 2 == 0 ) return false;
	for( long long i = 3; i * i <= x; i += 2 ) {
		if( x % i == 0 ) return false;
	}
	return true;
}

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

	long long gcd = __gcd( A, B );
	map<long long, int> m;
	long long g = gcd;
	for( long long i = 2; i * i <= g; i++ ) {
		while( g % i == 0 ) {
			m[i]++;
			if( g / i != i ) m[g / i]++;
			g /= i;
		}
	}
	m[1]++;
	if( gcd != 1 ) {
		m[gcd]++;
	}
	int ans = 0;
	for( auto it = m.begin(); it != m.end(); it++ ) {
		if( it->first == 1 || isPrime( it->first ) ) ans++;
	}

	cout << ans << endl;
}

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

int N;
string S;
string ans;

bool chk_anim(void) {
	for (int i = 2; i <= N + 1; ++i) {
		char ox = (i < N + 1) ? S[i - 1] : S[0];
		if ((ox == 'o' && ans[i - 1] == 'S') || (ox == 'x' && ans[i - 1] == 'W'))
			ans[i] = ans[i - 2];
		else
			ans[i] = (ans[i - 2] == 'S') ? 'W' : 'S';
	}

	if (ans[N] == ans[0] && ans[N + 1] == ans[1]) {
		ans.erase(N);
		return true;
	}
	else
		return false;
}

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

	ans.resize(N + 2, ' ');
	ans[0] = 'S';	ans[1] = 'S';
	bool flag = chk_anim();
	if (!flag) {
		ans[0] = 'S';	ans[1] = 'W';
		flag = chk_anim();
	}
	if (!flag) {
		ans[0] = 'W';	ans[1] = 'S';
		flag = chk_anim();
	}
	if (!flag) {
		ans[0] = 'W';	ans[1] = 'W';
		flag = chk_anim();
	}

	if (flag)
		cout << ans << '\n';
	else
		cout << "-1" << '\n';
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
using namespace std;
int main(){
    int n,m,g[30][30]={},k,a,cnt=0,f;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            scanf("%d",&a);
            g[i][a-1]=1;
        }
    }
    for(int i=0;i<m;i++){
        f=1;
        for(int j=0;j<n;j++){
            f*=g[j][i];
        }
        cnt+=f;
    }
    printf("%d\n",cnt);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
// Begin Header {{{
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<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define rll(x) (x).rbegin(), (x).rend()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	ll n, sum=0;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(rll(a));
	sum += a[0];
	ll cnt = n-2;
	loop(i, 1, n){
		if(cnt == 0) break; 
		sum+=a[i]; cnt--;
		if(cnt == 0) break;
		sum+=a[i]; cnt--;
	}
	cout << sum << endl;
	return 0;
}

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


int main(int argc, char** argv){
  int N, M;
  cin >> N >> M;
  int tmpt;
  long long tmpd;
  priority_queue<pair<long long, int>> que;
  vector<pair<long long, int>> vec;
  for(int cnt0=0; cnt0<N; cnt0++) {
    cin >> tmpt >> tmpd;
    que.push(make_pair(tmpd, tmpt));
  }
  long long ans=0;
  map<int, int> mp;
  for(int cnt0=0; cnt0<M; cnt0++) {
    ans+=que.top().first;
    mp[que.top().second]++;
    vec.push_back(que.top());
    que.pop();
  }
  long long sz = mp.size();
  ans += sz*sz;
  sort(vec.begin(), vec.end());

  long long tmpans = ans;
  for(int cnt0=0; cnt0 < M; cnt0++){
    if(mp[vec[cnt0].second] == 1) continue;
    while(que.size()){
      pair<long long, int> q = que.top(); que.pop();
      if(mp[q.second] == 0){
          tmpans = tmpans - vec[cnt0].first + q.first -sz*sz + (sz+1)*(sz+1);
          sz++;
          ans = max(ans, tmpans);
          mp[vec[cnt0].second]--;
          mp[q.second]++;
          vec[cnt0] = q;
          break;
      }
    }
  }
  printf("%lld\n", ans);  
  return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
const ll mod=1e9+7;
ll pow_3[MAXN];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string l;
	cin>>l;
	int sz=l.size();
	pow_3[0]=1;
	for(int i=1;i<MAXN;i++)
	{
		pow_3[i]=pow_3[i-1]*3ll;
		pow_3[i]%=mod;
	}
	ll ans=pow_3[sz-1];
	ll fans=0;
	ll curr_ans=1;
	for(int i=1;i<sz;i++)
	{
		if(l[i]=='1')
		{
			fans=fans+(curr_ans*pow_3[sz-i-1])%mod;
			if(fans>=mod)
			{
				fans-=mod;
			}
			curr_ans=curr_ans*2ll;
			curr_ans%=mod;
		}
	}
	fans=fans+curr_ans;
	if(fans>=mod)
	{
		fans-=mod;
	}
	fans=fans*2ll;
	if(fans>=mod)
	{
		fans-=mod;
	}
	ans=ans+fans;
	if(ans>=mod)
	{
		ans-=mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int h[n], l[n];
    for (int i=0; i<n; i++) cin >> h[i];

    int sum = 0;
    for (int i=0; i<n; i++) {
        int sw = 1;
        for (int j=0; j<i; j++) {
            if (h[j] > h[i]) {
                sw = 0;
                break;
            }
        }
        if (sw) sum++;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[] age = new int[7];
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				age[a > 60 ? 6 : a / 10]++;
			}
			for (int t : age)
				System.out.println(t);
		}

	}
}

Measured memory_bytes: 209408
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def calc(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

def main():
    n = int(ipt())
    num = [0]*(n+1)
    for x in range(1,n):
        if calc(x,1,1) > n:
            break
        for y in range(1,n):
            if calc(x,y,1) > n:
                break
            for z in range(1,n):
                ci = calc(x,y,z)
                if ci > n:
                    break
                num[ci] += 1
    for i in num[1::]:
        print(i)

    return None

if __name__ == '__main__':
    main()


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

signed main() {
  string s;cin>>s;
  string t[3] = {"Sunny", "Cloudy", "Rainy"};
  for(int i=0;i<3;++i){
    if(s==t[i]){
      cout<<t[(i+1)%3]<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  if(a>b) swap(a,b);
  if((a+b)%2==0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int main(){
        string s[2];
        for(int i=0;i<2;i++)cin>>s[i];
        int a[2];
        for(int i=0;i<2;i++)cin>>a[i];
        string u;cin>>u;
        if(u==s[0])a[0]--;
        if(u==s[1])a[1]--;

        cout<<a[0]<<" "<<a[1]<<endl;
    }
        






Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main(){
string S; 
long long int K; 
cin >> S >> K; 
int A = -1; 
int M = 1; 
for(int i = 0; i < S.size(); i++){
M = max(M, ctoi(S.at(i))); 
if(ctoi(S.at(i)) >= 2){
A = i; 
break; 
}
}
if(A == -1) cout << 1 << endl; 
else if(M >= 2 && K <= A) cout << 1 << endl; 
else cout << M << endl; 
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int A, B, C;
/**********************************/

void codeB() {
    int top = max(A, max(B, C));
    if(top%2==(A+B+C)%2) {
        cout << (3*top-A-B-C)/2 << endl;
    }
    else {
        cout << (3*(top+1)-A-B-C)/2 << endl;
    }
}

void codeA() {
    int ans = 0;
    int a = A%2;
    int b = B%2;
    int c = C%2;
    if(a==b&&b!=c) {
        A++; B++;
        ans++;
    }
    else if(b==c&&a!=c) {
        B++; C++;
        ans++;
    }
    else if(c==a&&b!=c) {
        C++; A++;
        ans++;
    }
    int top = max(A, max(B, C));
    ans += (3*top-A-B-C)/2;
    cout << ans << endl;
}

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

    cin>>A>>B>>C;
    //codeA();
    codeB();
}


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

int main(){
    int n;
    cin >> n;
    
    int ans = 0;
    n /= 2;
    while(n>0){
        ans++;
        n /= 2;
    }

    cout << (1<<ans) << endl;
}

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

class Edge{
public:
	int to,cap,cost,rev;
	Edge(int to,int cap,int cost,int rev){
		this->to=to; this->cap=cap; this->cost=cost; this->rev=rev;
	}
};

const int V=367,INF=1<<28;
vector<Edge> G[V];
int dist[V],prevv[V],preve[V];

int minCostFlow(int s,int t,int f) {
	int ret=0;
	while(f>0){
		fill(begin(dist), end(dist), INF);
		dist[s]=0;
		bool update=true;
		while(update){
			update=false;
			for(int v=0; v<V; ++v){
				if(dist[v]==INF)	continue;
				for(int i=0; i<G[v].size(); ++i){
					Edge e = G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.cost){
						dist[e.to]= dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						update=true;
					}
				}
			}
		}
		if(dist[t]==INF)	return -1;
		int d=f;
		for(int v=t; v!=s; v=prevv[v])	d = min(d, G[prevv[v]][preve[v]].cap);
		f-=d;
		ret += d*dist[t];
		for(int v=t; v!=s; v=prevv[v]){
			Edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return ret;
}

void addEdge(int from,int to,int cap,int cost){
	G[from].push_back(Edge(to, cap, cost, G[to].size()));
	G[to].push_back(Edge(from, 0, -cost, G[from].size()-1));
}

int solve(int N){
	fill(begin(G), end(G), vector<Edge>());
	fill(begin(dist), end(dist), INF);
	fill(begin(prevv), end(prevv), 0);
	fill(begin(preve), end(preve), 0);
	for(int i=1; i<V; ++i)	addEdge(i-1, i, 2, 0);
	int a,b,c;
	for(int i=0; i<N; ++i){
		cin>>a>>b>>c;
		addEdge(a, b+1, 1, -c);
	}
	int ret = minCostFlow(0, V-1, 2);
	return -ret;
}

int main(){
	int N;
	while(cin>>N, N)	cout<< solve(N) <<endl;
	return 0;
}

Measured memory_bytes: 1340
#include <string.h> 
#include <iostream> 
using namespace std; 
  
int main() 
{ 
int k,a,b;
cin>>k>>a>>b;
for(int i=a;i<=b;i++){
    if(i%k==0){
     cout<<"OK";
     return 0;}
}
cout<<"NG";
return 0;}

Measured memory_bytes: 3644
import sys

def main():
    input = sys.stdin.readline
    S = [str(c) for c in input().strip()]
    X, Y = map(int, input().split())
    F = []
    while len(S) > 0:
        f = 0
        while len(S) > 0 and S[0] == 'F':
            f += 1
            S.pop(0)
        F.append(f)
        if len(S) > 0:
            S.pop(0)

    Fx = []
    Fy = []
    for i in range(1, len(F)):
        if i % 2 == 0:
            Fx.append(F[i])
        else:
            Fy.append(F[i])

    dpx = [[F[0]]] + [0] * len(Fx)
    for i in range(len(Fx)):
        nx = set()
        for a in dpx[i]:
            nx.add(a + Fx[i])
            nx.add(a - Fx[i])
        dpx[i+1] = nx

    dpy = [[0]] + [0] * len(Fy)
    for i in range(len(Fy)):
        ny = set()
        for a in dpy[i]:
            ny.add(a + Fy[i])
            ny.add(a - Fy[i])
        dpy[i+1] = ny


    if X in dpx[-1] and Y in dpy[-1]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 359820
n=int(input())
A=list(map(int,input().split()))
m=int(200200)
B=[0]*m

for i in range(n):
    B[A[i]]+=1

a=int(0)
for i in range(m):
    a+=int((B[i]-1)*B[i]/2)

for i in range(n):
    print(a-B[A[i]]+1)

Measured memory_bytes: 24748
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;
typedef long long ll;

int main(void){
    using namespace  std;
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) a[i] = 1;

    rep(i, K){
        int d;
        cin >> d;
        vector<int> A(d);
        rep(k, d) cin >> A[k];
        rep(k, d) a[A[k] - 1] = 0;
    }

    int ret = 0;
    rep(i, N)
        ret += a[i];
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3636