akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    int n, m;
    cin >> n >> m;
    int sum = n;
    for(int i = 0; i < m; ++i) {
        int a; cin >> a;
        sum -= a; 
    }
    if(sum < 0)
        cout << -1 << '\n';
    else
        cout << sum << '\n';
    
    
    return 0;
}


Measured memory_bytes: 3660
x, n = map(int, input().split())
P = set(map(int, input().split()))
if n==0:
    print(x)
elif n==100 and x<=50:
    print(0)
elif n==100 and 50<x:
    print(101)
else:
    T = set(list(range(-1, 102))) - P
    diff = 101
    for t in T:
        if diff > abs(x-t):
            diff = abs(x-t)
            ans = t
    print(ans)

Measured memory_bytes: 9120
import java.util.*;

public class Main
{
	public static void main (String[] args)
	{
		Scanner sc = new Scanner (System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();


		if((a-(b*2))<0)
			System.out.println (0);
		else
			System.out.println (a-(b*2));



	}
}

Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int a[100000], b[100000];
	int c[100001]={}, cs[100001];
	for(int i=0; i<m; i++){
		scanf("%d %d", &a[i], &b[i]);
		c[a[i]]++;
	}
	cs[0]=0;
	for(int i=1; i<=n; i++){
		cs[i]=cs[i-1]+c[i];
	}
	int as[100000], bs[100000];
	for(int i=0; i<m; i++){
		bs[cs[a[i]]-c[a[i]]]=b[i];
		as[cs[a[i]]-c[a[i]]]=a[i];
		c[a[i]]--;
	}
	int ans=1;
	int b0=bs[0];
	for(int i=0; i<m; i++){
		if(as[i]>=b0){
			ans++;
			b0=bs[i];
		}else{
			b0=min(b0, bs[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560
N, M = gets.split(/ /).collect{|n| n.to_i}

list = [[], [true, 1]]

(2..N).each{|i|
	list[i] = [false, 1]
}

M.times{
	x, y = gets.split(/ /).collect{|n| n.to_i}
	list[y][1] += 1
	list[x][1] -= 1
	if list[x][0]
		list[y][0] = true
		if list[x][1] == 0
			list[x][0] = false
		end
	end
}

count = 0
list.each{|flag, num|
	if flag
		count += 1
	end
}
puts count


Measured memory_bytes: 11388
import copy

ls = []

S = str(input())
l = list(S)

h = 0

for i in range(len(l)):
    for j in range(len(l) - i):
        ls = copy.copy(l)
        del ls[i : i + j]
        b = "".join(ls)
        if(b == "keyence"):
            h = 1

if(h == 1):
    print("YES")
else:
    print("NO")


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

int main()
{
  int cnt = 0;
  string s, t;
  while (cin >> s) {
    t = s;
    reverse(t.begin(), t.end());
    if (s == t)
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;

#define endl '\n'


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

    ll n,a,b;
    cin>>n>>a>>b;

    cout<<min(n*a,b)<<endl;

}









Measured memory_bytes: 256
N,W = map(int,input().split())
V = [list(map(int,input().split())) for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for w in range(W+1):
    for i in range(N):
        if w >= V[i][1]:
            dp[i+1][w] = max(dp[i][w-V[i][1]]+V[i][0],dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[-1][-1])


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

using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  
  vector< int > ck( s.size() );

  for ( int i = 0; i < s.size(); i++ ){
    if( s[ i ] != t[ i ] ){
      char tmp = s[ i ];
      s[ i ] = t[ i ];
      ck.at( i ) = 1;
      for ( int j = 0; j < s.size(); j++ ){
        if ( j == i ) continue;
        if ( s[ j ] == tmp ){
          s[ j ] = t[ i ];
          if ( ck.at( j ) ){
            cout << "No" << endl;
            return 0;
          }
        } else if ( s[ j ] == t[ i ] ){
          s[ j ] = tmp;
          if ( ck.at( j ) ){
            cout << "No" << endl;
            return 0;
          }
        }
      }
    }
  }
  for ( int i = 0; i < s.size(); i++ ){
    if( s[ i ] != t[ i ] ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  if ( a % 3 == 0 || b % 3 == 0 || ( a + b ) % 3 == 0 ){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  } 
  
}



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

using namespace std;

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

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

    int q;
    cin >> q;

    vector<int> t(q);
    for (int i = 0; i < q; ++i)
        cin >> t[i];

    int count = 0;
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < n; ++j) {
            if (s[j] ==  t[i]) {
                ++count;
                break;
            }
        }
    }

    cout << count << '\n';
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <utility>

using namespace std;

class Station {
public:
  int to;
  int cost;
  int time;
  Station(){
	to = cost = time = 0;
  }
  Station( const int to, const int cost, const int time ){
	this->to = to;
	this->cost = cost;
	this->time = time;
  }
};

class mycmp
{
public:
  bool operator() ( pair<int, int>& lhs, pair<int, int>& rhs )
  {
	return lhs.second > rhs.second;
  }
};

const int COST = 0;
const int TIME = 1;

int solve( const int p, const int q, const int r,
		   const vector<vector<Station> > table ) {

  priority_queue<pair<int, int>, vector<pair<int, int> >, mycmp > que;
  que.push( make_pair( p, 0 ) );

  set<int> visited;
  
  while ( !que.empty() ) {
  	auto elem = que.top();
  	const int stat = elem.first;
  	const int cost = elem.second;
  	que.pop();
	
  	if ( stat == q ) {
  	  return cost;
  	} else if ( visited.find( stat ) == visited.end() ) {
  	  visited.insert( stat );
  	  for ( const Station s : table[stat] ) {
  		if ( r == COST ) {
  		  que.push( make_pair( s.to, cost + s.cost ) );
  		} else {
  		  que.push( make_pair( s.to, cost + s.time ) );
  		}
  	  }
  	}	
  }
  return -1;
}
  
int main() {
  
  while ( true ) {
   	int n, m;
   	cin >> n >> m;
   	if ( n == 0 && m == 0 ) break;
	vector<vector<Station> > table(m + 1);
	for ( int i = 0; i < n; i++ ) {
	  int from, to, cost, time;
	  cin >> from >> to >> cost >> time;
	  table[ from ].push_back( Station( to, cost, time ) );
	  table[ to ].push_back( Station( from, cost, time ) );
	}
	int k;
	cin >> k;
	for ( int i = 0; i < k; i++ ) {
	  int p, q, r;
	  cin >> p >> q >> r;
	  cout << solve( p, q, r, table ) << endl;
	}
  }  
}

Measured memory_bytes: 1444
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
  long long h,n;
  cin >> h >> n;
  long long a[n];
  rep(i,n){
    cin >> a[i];
  }
sort(a,a+n,greater<long long>());
ll sum=0;
bool ok=false;
rep(i,n){
    h-=a[i];
    if(h<=0) ok = true;
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
 }


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

#define INF (long long)1e17
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define qq queue
#define w(n) while(n--)
#define for0(i, n) for(i = 0; i < n; i++)
#define for1(i, n) for(i = 1; i <= n; i++)

#define MAXN 100001
ll stone[MAXN], dp[MAXN][2], n;

ll solve(int x, int j) {
    int reach = x + j;

    if (x >= n) return 0;
    if (reach > n) return INF;
    if (dp[x][j-1] != -1) return dp[x][j-1];
    
    ll res = min(solve(reach, 1), solve(reach, 2));
    dp[x][j-1] = res + abs(stone[reach] - stone[x]); 
    
    return dp[x][j-1];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int i, j;
    for0(i, MAXN) {
        for0(j, 2) {
            dp[i][j] = -1;
        }
    }
    
    cin >> n;
    
    for1(i, n) {
        cin >> stone[i];
    }
    
    ll res1 = solve(1, 1);
    ll res2 = solve(1, 2);
    ll res = min(res1, res2);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
int l[17];
int n,aa,bb,cc;
int ans=1e9;
void dfs(int x,int a,int b,int c,int s){
    if(x>n){
        if(a&&b&&c)
            ans=min(ans,s+abs(aa-a)+abs(bb-b)+abs(cc-c));
        return;
    }
    dfs(x+1,a,b,c,s);
    dfs(x+1,a+l[x],b,c,s+10*(a>0));
    dfs(x+1,a,b+l[x],c,s+10*(b>0));
    dfs(x+1,a,b,c+l[x],s+10*(c>0));
}
int main(){
    scanf("%d%d%d%d",&n,&aa,&bb,&cc);
    for(int i=1;i<=n;i++)
        scanf("%d",&l[i]);
    dfs(1,0,0,0,0);
    printf("%d",ans);
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
LL MOD = 1e9+7;
LL INF = 1e9;

string t;
int l;
int v[11];
int var(int i)
{
    return v[i];
}

int e1()
{
    if(t[l]=='(')
    {
        l++;
        int p=e1(),r;
        l++;
        switch(t[l-1])
        {
            case '*':
            r=e1();
            l++;
            return p*r;
            
            case '+':
            r=e1();
            l++;
            return p+r>=1?1:0;
            
            case '-':
            l++;
            r=e1();
            l++;
            return (1-p)+r>=1?1:0;
        }
    }
    
    if(t[l]=='-')
    {
        l++;
        return 1-e1();
    }
    else if(t[l]=='T')
    {
        l++;
        return 1;
    }
    else if(t[l]=='F')
    { 
        l++;
        return 0;
    }
    else return var(t[l++]-'a');    
}

int main()
{
    string s;
    while(cin>>s,s!="#")
    {
        string s1,s2;
        REP(i,s.size())
        {
            if(s[i]=='=')
            {
                s1=string(s.substr(0,i));
                s2=string(s.substr(i+1));
            }
        }
        int r,p;bool flag=true;
        REP(i,1<<11)
        {
            REP(j,11)
            {
                v[j]=(i>>j)&1;
            }
            
            t=s1;l=0;
            p=e1();
            t=s2;l=0;
            r=e1();
            if(r!=p)
            {
                flag=false;
                break;
            }
        }
        
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

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

int main() {
  bool found[26];
  for(int i=0;i<26;i++)found[i]=false;
  string s;
  cin >> s;
  for(int i=0;i<s.length();i++)found[s[i]-'a']=true;
  for(int i=0;i<26;i++){
    if(found[i]){
      if(i==25)cout << "None";
      continue;
    }
    else{
      char c='a'+i;
      cout << c;
      break;
    }
  }
}

Measured memory_bytes: 512
def main():
    N,M  = map(int,(input().split()))
    BOX = [0]+[1]*N
    RED = [False]*(N+1)
    RED[1] = True

    for _ in range(M):
        x,y = map(int,(input().split()))
        BOX[x] -=1
        BOX[y] +=1
        if RED[x]:
            RED[y]=True
        if BOX[x]==0:
            RED[x]=False
    cnt = 0
    for r in RED:
        if r:
            cnt +=1
    print(cnt)



if __name__ == '__main__':
    main()


Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

#define mod 1000000007

int main(){
  long long i,n,k,ans=0,min,max;
  cin>>n>>k;
  for(i=k;i<=n+1;i++){
    min=(i*(i-1))/2;
    max=(i*((2*n)-i+1))/2;
    ans=ans+(max-min)+1;
  }
  ans=ans%mod;
  cout<<ans<<endl;
  return 0;
}

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



map<string,ll>mp;
map<string,ll>vis;
string sx[sz],s;

int main()
{


   ll n,i,j,c=0,d,k,p,mx=0,a,b;




   cin>>n;

   for(i=1;i<=n;i++)
   {
       cin>>sx[i];
       mp[sx[i]]++;
       mx=max(mx,mp[sx[i]]);
   }

  sort(sx+1,sx+n+1);
  //cout<<mx<<endl;

  for(i=1;i<=n;i++)
  {
      if(mp[sx[i]]==mx && vis[sx[i]]==0)
      {
          cout<<sx[i]<<endl;
          vis[sx[i]]=1;
      }
  }



  return 0;
}



Measured memory_bytes: 39296
#include<stdio.h>
int main()
{
    int a;
    int i=0,m=0,n;
    scanf("%d",&a);
    n=a;
    for(i=0;i<n/10+1;i++)
    {
        m+=a%10;
        a/=10;
	}
    if(n%m==0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;   
} 

Measured memory_bytes: 128
fn a() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("input error");
    let nm: Vec<u32> = input.split_whitespace()
        .map(|s| s.parse::<u32>().expect("parse error"))
        .collect();

    let a = if nm[0] > 0 { nm[0] * (nm[0] - 1) / 2 } else { 0 };
    let b = if nm[1] > 0 { nm[1] * (nm[1] - 1) / 2 } else { 0 };

    println!("{}", a + b);
}

fn main() {
    a();
}

Measured memory_bytes: 4352
program main
  implicit none
  integer :: h,w,i,j
  integer,allocatable :: x(:,:)
  character(50) :: s

  read(*,*) h,w
  allocate(x(0:h+1,0:w+1))
  x(:,:)=0

  do i=1,h
     read(*,*) s
     do j=1,w
        if(s(j:j)=='#')then
           x(i,j)=1
        else
           x(i,j)=0
        endif
     enddo
  enddo

  do i=1,h
     do j=1,w
        if(x(i,j)==1)then
           if(x(i,j-1)==1)then
              cycle
           else if(x(i,j+1)==1)then
              cycle
           else if(x(i+1,j)==1)then
              cycle
           else if(x(i-1,j)==1)then
              cycle
           else
              write(*,*) 'No'
              stop
           endif
        endif
     enddo
  enddo

  write(*,*) 'Yes'

  stop

end program main

Measured memory_bytes: 2652
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n,h,w;
  cin>>n>>h>>w;
  int cnt =0;
  REP(i,0,n){
    LL a,b;
    cin>>a>>b;
    if(a>=h && b>=w)++cnt;
  }
  cout<<cnt<<endl;

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    char t = s[0];
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(t != s[i]){
            cnt++;
            t = s[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
S=input()
# S="akasakaakasakasakaakas"

for i in range(1,len(S)):
    s=S[:-1*i]
    if len(s)%2==0:
        head=s[:len(s)//2]
        tail=s[len(s)//2:]
        if head==tail:
            print(len(s))
            break
        else:
            pass
    else:
        continue


Measured memory_bytes: 9088
#include<stdio.h>
int main(){
    int l, r, d, ctr=0;
    scanf("%d %d %d", &l, &r, &d);
    
    for(int i=l; i<=r; i++){
        if(i%d == 0){
            ctr++;
        }
    }
            printf("%d ", ctr);

    return 0;
}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  int a, b, x;
  cin >> a >> b >> x;
  int xa = x-a;
  if(xa<0) cout << "NO" << endl;
  else if(xa<=b) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = MAP()
prev = -INF
ans = 0
for a in A:
    if a < prev:
        ans += (prev - a)
    else:
        prev = a
print(ans)


Measured memory_bytes: 44068
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

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

    bool can = false;
    if (a % 3 == 0){
        can = true;
    }
    else if (b % 3 == 0){
        can = true;
    }
    else if((a + b) % 3 == 0){
        can = true;
    }

    if (can) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]


#新しい値が最小なら追加，そうでなければそれを超えない最大の値を書き換え
#降順
b=[]
b.append(A[0])


def bi_s(n):
    if b[-1]>=n:
        return -1
    if n>b[0]:
        return 0
    
    ceil=0
    floor=len(b)-1
    med=1#len(b)==2のとき
    while abs(floor-ceil)>1:
        med=(ceil+floor)//2
        if n>b[med]:
            floor=med
        else:
            ceil=med
    return floor

for i in range(1,N):
    index=bi_s(A[i])
    if index==-1:
        b.append(A[i])
    else:
        b[index]=A[i]
print(len(b))

Measured memory_bytes: 56024
#include <iostream>
#include <vector>
#include <map>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> arr(n);
  for (int& e : arr) {
     std::cin >> e;
  }
  
  std::map<long, int> mp;
  ++mp[0];
  long sum = 0;
  long ans = 0;
  for (int e : arr) {
    sum += e;
    ans += mp[sum];
    ++mp[sum];
  }
  
  std::cout << ans << std::endl;
}


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

#define ln '\n'
#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 FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans;
    cin >> ans;
    REP(i, n - 1) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << ln;
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
  int N, r = 0,  b = 0;
  string s;
  cin >> N;
  cin >> s;

  for (int i = 0; i < N; i++) {
    if (s[i] == 'R') {
      r++;
    } else {
      b++;
    }
  }

  if (r > b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastio cin.sync_with_stdio(false); cin.tie(NULL)
using namespace std;

ll re=0;
string s;
void adding(ll n,int pos,ll sum){
  if (pos<s.size()){
    adding(n*10+(ll)(s[pos]-'0'),pos+1,sum);
    adding((ll)(s[pos]-'0'),pos+1,sum+n);
  }
  else{
    re+=sum+n;
  }
}

int main(){
  cin>>s;
  adding((ll)(s[0]-'0'),1,0LL);
  cout<<re<<'\n';
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

map<string,int>ma;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    string s,ss;
    cin>>s>>ss;
    if(s == "insert"){
      ma[ss] = 1;
    }else{
      if(ma[ss])cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 47464
x1, y1, x2, y2 = map(int, input().split())

vx, vy = (x2 - x1, y2 - y1)

vx, vy = (-vy, vx)
x3, y3 = (x2 + vx, y2 + vy)

vx, vy = (-vy, vx)
x4, y4 = (x3 + vx, y3 + vy)

print(x3, y3, x4, y4)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
//#define int long long


int h[100005];
int mem[100005];
int dp(int i){
    if(mem[i]!= -1)
        return mem[i];
    if(i < 1)
        return INF;
    if(i==1)
        return 0;
    int a1 = dp(i-1) + abs(h[i]-h[i-1]);
    int a2 = dp(i-2) + abs(h[i]-h[i-2]);

    return mem[i] = min(a1,a2);
}

inline void solve(){

    int n;
    cin >> n;
    memset(mem,-1,sizeof(mem));
    
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }

    cout << dp(n) << endl;

}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 4224
import math
s = int(input())
root = math.ceil(s**0.5)
#print("root",root)
diff = abs(root**2 - s)
#print("diff",diff)
pf=[]
a = 0
b = 0
#print(int(diff**0.5))
if diff != 1:
  if diff == 2:
    a = 1
    b = 2
  elif diff == 3:
    a = 1
    b = 3
  else:
    test = int(diff**0.5)+1
    for i in range(2, test):
      #print("diffloop",diff)
#      if i == 1710:
#        print("1710diff",diff)
#      if i ==25322:
#        print("25322diff",diff%i)
      while diff%i==0:
        pf.append(i)
        diff//=i
#        print("i",i,"diff",diff)
    if diff>1:pf.append(diff)
    for i in range(len(pf)):
      if(i%2==0):
        if a ==0:
          a = 1
        a*=pf[i]
      else:
        if b ==0:
          b = 1
        b*=pf[i]
else:
  a = 1
  b = 1
if a != 0 and b == 0:
  b = 1
if b != 0 and a == 0:
  a = 0
if a > 10**9:
  a /= pf[0]
  b *= pf[0]
if b > 10**9:
  a *= pf[0]
  b /= pf[0]
#print("pf",pf)
if a >= 0 and b >= 0:
  print("0","0",a,root,root,b)
elif a >= 0 and b < 0:
  print("0",-b,a,root-b,root,0)
elif a < 0 and b >= 0:
  print(-a,"0","0",root,root-a,b)
else:
  print(-a,-b,"0",root-b,root-a,"0")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cstring>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef pair<int, int> P;

const int INF = 1<<29;

P sec[101]; // cost value
P st[101];

int dpsec[1001];
int dpstd[101][1001];
int dp[1001];
int main(){
	int LIMIT, N, M, X;
	while(cin >> LIMIT >> N >> M >> X, LIMIT|N|M|X){
		rep(i, 1001) dp[i] = dpsec[i] = -INF;
		rep(j, 101) rep(i, 1001) dpstd[j][i] = -INF;
		rep(i, N){
			string s;
			cin >> s >> sec[i].X >> sec[i].Y;
		}
		rep(i, M){
			string s;
			cin >> s >> st[i].X >> st[i].Y;
		}
		rep(i, N){
			dpsec[sec[i].X] = max(dpsec[sec[i].X], sec[i].Y);
			for(int j = i+1; j < N; j++){
				dpsec[sec[i].X+sec[j].X] = max(dpsec[sec[i].X+sec[j].X], sec[i].Y+sec[j].Y);
			}
		}

		dpstd[0][0] = 0;
		rep(i, M){
			for(int j = i; j >= 0; j--){
				rep(k, LIMIT-st[i].X){
					if(dpstd[j][k] == -INF) continue;
					dpstd[j+1][k+st[i].X] = max(dpstd[j+1][k+st[i].X], dpstd[j][k]+st[i].Y);
				}
			}
		}

		rep(j, LIMIT){
			for(int i = X; i <= M; i++){
				dp[j] = max(dp[j], dpstd[i][j]);
			}
		}

		rep(i, LIMIT-1){
			dp[i+1] = max(dp[i], dp[i+1]);
			dpsec[i+1] = max(dpsec[i], dpsec[i+1]);
		}

		int ans = 0;
		rep(i, LIMIT){
			ans = max(ans, dp[i]+dpsec[LIMIT-i]);
		}
		cout << ans << endl;
	}

	return 0;
}

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

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,a,b,c,d,h,w,x,y;
string str;

signed main(){
  cin >> str;
  FOR(i,str.length()){
    cout <<str[i];
    if(i==3) cout ___;
  }
  
  cout fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

using namespace std;

string A;

int IsPalindrom(string s) {
	
	string t = s;

	reverse(t.begin(), t.end());

	if (s == t) { return 1; }

	return 0;

}

long long int N;

long long int C[30];

int main(void) {

	cin >> A;

	N = A.size();

	

	long long int ans = (N*(N - 1)) / 2 + 1;

	for (int i = 0; i < N; i++) {
		C[A[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		//cout << "C[" << i << "]= " << C[i] << endl;
		
		ans -= (C[i] * (C[i] - 1)) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X = int(input())
	ans = int(X // 200)
	print(10 - ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 9508
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
#include <algorithm>
#include<vector>
using namespace std;

int abs(int a){
	if(a<0)return -a;
	return a;
}





long long N,M,re,C;
bool map[51][51];
long long ans,D[30][30],c[501][501],F[501],ti[501],blank,one[30],two[30],three[30],x,y,z;
string s;

int main(){
	cin>>N>>C;
	x=y=z=0;
	for(int i=1;i<C+1;i++){
		for(int j=1;j<C+1;j++){
		cin>>D[i][j];
		}
	}
	for(int i=1;i<N+1;i++){
		for(int j=1;j<N+1;j++){
			cin>>c[i][j];
			if((i+j)%3==1){
				one[c[i][j]]++;
			}
			if((i+j)%3==2){
				two[c[i][j]]++;
			}
			if((i+j)%3==0){
				three[c[i][j]]++;

			}
		}
	}
	re=0;
	ans=2000000000;
	for(int i=1;i<C+1;i++){
		for(int j=1;j<C+1;j++){
			if(i!=j){
				for(int k=1;k<C+1;k++){
					if(i!=k&&j!=k){
						for(int l=1;l<C+1;l++){
						re+=D[l][i]*one[l];
						re+=D[l][j]*two[l];
						re+=D[l][k]*three[l];
						}
						ans=min(ans,re);
						re=0;
					}
				}
			}
		}
	}



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2176
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	int n,T;
	scanf("%d%d", &n,&T);

	int c, t;
	int cost = INF;
	REP(i, n) {
		scanf("%d%d", &c, &t);
		if (t <= T) {
			cost = Min(cost, c);
		}
	}
	if (cost == INF) {
		puts("TLE");
	}
	else {
		PRINTD(cost);
	}
}

Measured memory_bytes: 128
N = int(input())
AB = [ list(map(int, input().split())) for _ in range(N) ]

cnt = 0
BA = [[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1] = AB[i][0]
    BA[i][0] = AB[i][1]
BA.sort()
for i in range(N):
    cnt += BA[i][1]
    BA[i][1] = cnt
ans = "Yes"
for i in range(N):
    if BA[i][0] < BA[i][1]:
        ans = "No"
        break

print(ans)


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    vector<ll> x(N);
    ll num = 0;
    REP(i, N)
    {
        if (i % 2 == 0) num += A[i];
        else num -= A[i];
    }
    x[0] = num / 2;
    for (int i = 1; i < N; ++i) x[i] = A[i - 1] - x[i - 1];
    REP(i, N) cout << 2 * x[i] << " ";
}


Measured memory_bytes: 2816
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=5010;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,A,B;
LL f[N][N];

int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(A),sc(B);
	for (int i=1; i<=n; i++)
	{
		int x; sc(x);
		memset (f[i],127,sizeof (LL)*(n+1));
		for (int j=0; j<=n; j++)
		{
			if (x< j) f[i][j]=f[i-1][j]+B;
			else if (x> j) f[i][j]=f[i-1][j]+A;
		}
		for (int j=0; j<=x; j++)
			chkmin (f[i][x],f[i-1][j]);
	}
	LL ans=1e18;
	for (int i=0; i<=n; i++)
		chkmin (ans,f[n][i]);
	pr(ans);

    return 0;
}


Measured memory_bytes: 195840
#include<bits/stdc++.h>
using namespace std;
int main(){
  string M;cin>>M;bool N=false,W=false,S=false,E=false;
  for(int X=0;X<M.size();X++){
    if(M[X]=='N')N=true;
    if(M[X]=='W')W=true;
    if(M[X]=='S')S=true;
    if(M[X]=='E')E=true;
  }
  if(S==N&&E==W)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    int64_t t,n,m,a,b,c,d,e,i,j,k,x,y,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>a>>b;
    if((a+b)&1) cout<<"IMPOSSIBLE"<<endl;
    else cout<<(a+b)/2<<endl;
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  vector<int> x(M), y(M), c(M);
  rep(i, M) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
  }

  int min_cost = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  rep(i, M) min_cost = min(min_cost, a[x[i]] + b[y[i]] - c[i]);
  cout << min_cost << endl;
  return 0;
}

Measured memory_bytes: 5052
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READAR(A,N);
    ll ans=1;
    FORI(i,0,N)
    {
        if(A[i]==0)
        {
            cout<<0<<endl;
            return 0;
        }
    }
    FORI(i,0,N)
    {
        if(A[i]>inf/ans)
        {
            cout<<-1<<endl;
            return 0;
        }
        ans=ans*A[i];
    }
    cout<<ans<<endl;
    return 0;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 4404
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 2019  # type: int

def solve(L: int, R: int):
    R = min(R, L + MOD)

    ret = 2020
    for i in range(L, R + 1):
        for j in range(L, R + 1):
            if j <= i:
                continue
            tmp = ((i % MOD) * (j % MOD)) % MOD
            ret= min(ret, tmp)
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    result = solve(L, R)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

int hw[1001][1001];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H>>W;
	char c;
	for (int h=1; h <= H; ++h) {
		for (int w = 1; w <= W; ++w) {
			cin >> c;
			if (c == '.') {
				hw[h][w] = 5000;
			}
		}
	}
	for (int h = 1; h <= H; ++h) {
		for (int w = 1; w < W; ++w) {
			hw[h][w + 1] = min(hw[h][w + 1], hw[h][w] + 1);
		}
	}
	for (int w = 1; w <= W; ++w) {
		for (int h = 1; h < H; ++h) {
			hw[h+1][w] = min(hw[h+1][w], hw[h][w] + 1);
		}
	}
	for (int h = 1; h <= H; ++h) {
		for (int w = W; w > 0; --w) {
			hw[h][w - 1] = min(hw[h][w - 1], hw[h][w] + 1);
		}
	}
	for (int w = 1; w <= W; ++w) {
		for (int h = H; h >0; --h) {
			hw[h-1][w] = min(hw[h-1][w], hw[h][w] + 1);
		}
	}
	int ans = 0;
	for (int h = 1; h <= H; ++h) {
		for (int w = 1; w <= W; ++w) {
			ans = max(hw[h][w], ans);
		}
	}
	cout << ans << endl;
	

}

Measured memory_bytes: 4224
import sys
from collections import defaultdict
def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    count1 = 0
    count2 = 0
    d = []
    l = defaultdict(int)
    
    for i in range(N):
        a,b = map(int, input().split())
        l[a] += b


    for i, j in sorted(l.items()):
        count2 += j
        if count2 >= K:
            print(i)
            break
        

        

if __name__ == "__main__":
    main()


Measured memory_bytes: 48092
N = int(input())
S = input()

max_chars = 0
for i in range(1, N):
    left = S[:i]
    right = S[i:]

    s1 = set()
    s2 = set()
    for l in left:
        s1.add(l)
    for r in right:
        s2.add(r)
    s3 = s1 & s2
    count = len(s3)
    if max_chars < count:
        max_chars = count
print(max_chars)



Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int N;
int F[100][10];
int P[100][11];

int main(){
    cin>>N;
    rep(i,N){
        rep(j,10){
            cin>>F[i][j];
        }
    }
    rep(i,N){
        rep(j,11){
            cin>>P[i][j];
        }
    }

    int ans=-1001001001;
    for(int i=1;i<1<<10;i++){
        int sum=0;
        rep(j,N){
            int c=0;
            rep(k,10){
                if(i>>k&F[j][k]) c++;
            }
            sum+=P[j][c];
        }
        ans=max(ans,sum);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
a,b,c,x=int(input()),int(input()),int(input()),int(input())
l=[]
for i in range(a+1):
    for j in range(b+1):
        if (x-500*i-100*j)%50==0 and 0<=(x-500*i-100*j)/50<=c:
            l.append(1)
            
print(len(l))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i,N){
		cin >> a[i];
	}
	vector<vector<int>>g(N);
	REP(i,N - 1){
		int a,b;
		cin >> a >> b;
		--a;--b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	vector<int>ans(N);
	auto dfs = [&](auto&&f,int now,int par,vector<int>&dp) -> void{
		auto itr = lower_bound(ALL(dp),a[now]);
		int prev = dp[itr - dp.begin()];
		dp[itr - dp.begin()] = a[now];
		ans[now] = lower_bound(ALL(dp),INF) - dp.begin();
		for(auto e:g[now]){
			if(e == par)continue;
			f(f,e,now,dp);
		}
		dp[itr - dp.begin()] = prev;
	};
	auto tmp = vector<int>(N,INF);
	dfs(dfs,0,-1,tmp);
	REP(i,ans.size())out(ans[i]);
}

Measured memory_bytes: 33264